#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdarg.h>
#include "cbl/assert.h"
#include "cbl/memory.h"
#include "hash.h"
Data Structures | |
struct | hash_t |
Functions | |
const char *() | hash_string (const char *str) |
returns a hash string for a string. | |
const char *() | hash_int (long n) |
returns a hash string for a signed integer. | |
const char *() | hash_new (const char *byte, size_t len) |
returns a hash string for a byte sequence. | |
size_t() | hash_length (const char *byte) |
returns the length of a hash string. | |
void() | hash_free (const char *byte) |
deallocates storage for a hash string. | |
void() | hash_reset (void) |
resets the hash table by deallocating all hash strings in it. | |
void | hash_vload (const char *str,...) |
puts a sequence of strings to the hash table. | |
void | hash_aload (const char *strs[]) |
puts given strings to the hash table. |
void hash_aload | ( | const char * | strs[] | ) |
puts given strings to the hash table.
hash_aload() takes strings from an array of strings (precisely, an array of pointers to char
) and puts them into the hash table. Since the function does not take the size of the string array there should be a way to mark end of the array, which a null pointer is for. hash_aload() is useful when a program needs to preload some strings to the hash table for later use. A variadic version is also provided; see hash_vload().
Possible exceptions: mem_exceptfail
Unchecked errors: none
[in] | strs | array of null-terminated strings |
void() hash_free | ( | const char * | byte | ) |
deallocates storage for a hash string.
hash_free() deallocates storage for a hash string, which effectively eliminates a hash string from the hash table. This facility is not used so frequently by user code that the original implementation did not provide it.
Possible exceptions: assert_exceptfail
Unchecked errors: hash string modified by user given for byte
[in] | byte | hash string to remove |
const char*() hash_int | ( | long | n | ) |
returns a hash string for a signed integer.
hash_int() returns a hash string for a given, possibly signed, integer whose type is long
.
Possible exceptions: mem_exceptfail
Unchecked errors: none
[in] | n | integer for which hash string returned |
size_t() hash_length | ( | const char * | byte | ) |
returns the length of a hash string.
Given a hash string, hash_length() returns its length.
Possible exceptions: assert_exceptfail
Unchecked errors: hash string modified by user given for byte
, foreign string given for byte
(only for faster version)
[in] | byte | byte sequence whose length returned |
const char*() hash_new | ( | const char * | byte, | |
size_t | len | |||
) |
returns a hash string for a byte sequence.
hash_new() returns a hash string for a given byte sequence, which may not end with a null character or may have a null character embedded in it. Even if it has "new" in its name, hash_new() just returns the existing hash string if there is already one created for the same byte sequence, which means there is only one instance of each byte sequence in the hash table and which is what hashing is for.
An empty byte sequence which contains nothing and whose length is 0 is also valid. But remember that byte
has a valid pointer value by pointing to a valid object even when len
is zero, since C allows no zero-sized object.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: hash string modified by user given for byte
[in] | byte | byte sequence for which hash string returned |
[in] | len | length of byte sequence |
void() hash_reset | ( | void | ) |
resets the hash table by deallocating all hash strings in it.
hash_reset() deallocates all hash strings in the hash table and thus resets it.
Possible exceptions: none
Unchecked errors: none
const char*() hash_string | ( | const char * | str | ) |
returns a hash string for a string.
hash_string() returns a hash string for a given null-terminated string. It is equivalent to call hash_new() with the string and its length counted by strlen(). Note that the trailing null character is not counted and it is appended when storing into the hash table. An empty string which is consisted only of a null character is also a valid argument for hash_string(); see hash_new() for details.
Possible exceptions: assert_exceptfail, mem_exceptfail
Unchecked errors: none
[in] | str | null-terminated string for which hash string returned |
void hash_vload | ( | const char * | str, | |
... | ||||
) |
puts a sequence of strings to the hash table.
hash_vload() takes a possibly empty sequence of null-terminated strings and puts them into the hash table. There should be a way to mark the end of the argument list, which a null pointer is for. hash_vload() is useful when a program needs to preload some strings to the hash table for later use. An array-version of hash_vload() is also provided; see hash_aload().
Possible exceptions: mem_exceptfail
Unchecked errors: none
[in] | str | null-terminated string to put to hash table |
[in] | ... | other such strings to put to hash table |