20 using namespace basis;
33 basis::un_int string_hasher::hash(
const void *key_data,
int key_length_in)
const
35 if (!key_data)
return 0;
36 if (key_length_in <= 1)
return 0;
39 abyte hashed[4] = { 0, 0, 0, 0 };
45 for (
int i = 0; i < key_length; i++) {
47 hashed[fill_posn] = hashed[fill_posn] + our_key[i];
49 if (fill_posn >= 4) fill_posn = 0;
51 hashed[fill_posn] = hashed[fill_posn] + (our_key[i] / 4);
54 for (
int k = key_length_in - 2;
55 (k >= 0) && (k >= key_length_in - 1 - key_length); k--) {
57 hashed[fill_posn] = hashed[fill_posn] + our_key[k];
59 if (fill_posn >= 4) fill_posn = 0;
61 hashed[fill_posn] = hashed[fill_posn] + (our_key[k] / 4);
65 for (
int j = 0; j < 4; j++) to_return = (to_return << 8) + hashed[j];
74 basis::un_int astring_hasher::hash(
const void *key_data,
int key_length_in)
const
76 if (!key_data)
return 0;
78 if (real_key->
length() + 1 != key_length_in) {
Provides a dynamically resizable ASCII character string.
int length() const
Returns the current length of the string.
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
A hashing algorithm takes a key and derives a related integer from it.
Implements a simple hashing algorithm for strings.
virtual basis::un_int hash(const void *key_data, int key_length) const
returns a value that can be used to index into a hash table.
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
unsigned int un_int
Abbreviated name for unsigned integers.
type minimum(type a, type b)
maximum returns the greater of two values.
A dynamic container class that holds any kind of object via pointers.
const int MAX_STRING_CHARS_USED