43 while (*p) { code = (code << 1) ^ *p; p++; }
52 if (key1 == key2)
return 0;
56 if (*p1 != *p2)
return -1;
59 if (!*p1 && !*p2)
return 0;
73 template <
class type_t>
77 for (n = size, buckets = 1; n != 1; n >>= 1)
95 template <
class type_t>
97 for (
int n = 0;
n < buckets;
n++) {
105 template <
class type_t>
107 for (
int n = 0;
n < buckets;
n++) {
121 template <
class type_t>
129 template <
class type_t>
140 for (n = buckets / 2; n < buckets; n++) {
table[
n] = NULL; }
144 for (n = 0; n < buckets / 2; n++){
146 for (e = 0; bucket && e < bucket->
size; e++) {
150 if ((next =
table[loc]) == NULL) {
155 if (next->
size == 1) fill++;
158 if (bucket->
size == 0) fill--;
167 for (n = buckets; n < buckets * 2; n++) {
169 if (bucket && bucket->
size) {
170 for (e = 0; e < bucket->
size; e++) {
172 if ((next =
table[loc]) == NULL) {
176 if (next->
size == 1) fill++;
191 template <
class type_t>
198 for (
int e = 0; e < bucket->
size; e++) {
199 if (bucket->
entry[e]->code == code) {
200 if (equals (bucket->
entry[e]->key, key) == 0) {
201 type_t * old = bucket->
entry[e]->value;
215 entry->
key = (
char *) malloc (keylen (key));
216 memcpy (entry->
key, key, keylen (key));
224 if (bucket->
size == 1) {
236 template <
class type_t>
242 for (
int n = 0;
n < bucket->
size;
n++) {
243 if (bucket->
entry[
n]->code == code) {
244 if (equals (bucket->
entry[
n]->key, key) == 0) {
245 value = bucket->
entry[
n]->value;
247 if (bucket->
size == 0) {
264 template <
class type_t>
269 for (
int n = 0;
n < bucket->
size;
n++) {
270 if (bucket->
entry[
n]->code == code)
271 if (equals (bucket->
entry[
n]->key, key) == 0)
272 return bucket->
entry[
n]->value;
279 template <
class type_t>
289 template <
class type_t>
294 _first = _last = _current = NULL;
298 template <
class type_t>
303 template <
class type_t>
309 template <
class type_t>
311 for (
int n = 0;
n < _hash->buckets;
n++) {
313 if (bucket && bucket->
size) {
316 _current = _first = bucket->
entry[_entry];
317 return _current->key;
320 _current = _first = NULL;
325 template <
class type_t>
327 for (
int n = _hash->buckets - 1;
n >= 0;
n--) {
329 if (bucket && bucket->
size) {
331 _entry = bucket->
size - 1;
332 _current = _last = bucket->
entry[_entry];
333 return _current->key;
336 _current = _last = NULL;
341 template <
class type_t>
344 if (bucket && _entry < bucket->
size - 1) {
346 _current = bucket->
entry[_entry];
347 return _current->key;
349 for (
int n = _bucket + 1;
n < _hash->buckets;
n++) {
350 bucket = _hash->table[
n];
351 if (bucket && bucket->
size) {
354 _current = bucket->
entry[_entry];
355 return _current->key;
363 template <
class type_t>
366 if (bucket && _entry > 0) {
368 _current = bucket->
entry[_entry];
369 return _current->key;
371 for (
int n = _bucket - 1;
n >= 0 ;
n--) {
372 bucket = _hash->table[
n];
373 if (bucket && bucket->
size) {
375 _entry = bucket->
size - 1;
376 _current = bucket->
entry[_entry];
377 return _current->key;
385 template <
class type_t>
387 return _current ? _current->key : NULL;
391 template <
class type_t>
397 template <
class type_t>
399 return _current ? _current->value : NULL;
403 template <
class type_t>
405 return _first ? _first->key : NULL;
409 template <
class type_t>
411 return _last ? _last->key : NULL;
type_t * currentVal(void)
type_t * put(char *, type_t *)
#define HASH_EXPAND_LIMIT
#define HASH_SHRINK_LIMIT
static int hash_code(char *key)
static int hash_key_equals(char *key1, char *key2)
hashentry< type_t > ** entry
#define HASH_LOCATION(code)
hash(int size=HASH_MIN_SIZE)
static unsigned hash_key_length(char *key)
void add(hashentry< type_t > *e)