Prototype for a Key hashing function.
More...
|
static size_t | gen_string_hash (union HashKey key, size_t num_elems) |
| Generate a hash from a string - Implements hash_gen_hash_t -.
|
|
static size_t | gen_case_string_hash (union HashKey key, size_t num_elems) |
| Generate a hash from a string (ignore the case) - Implements hash_gen_hash_t -.
|
|
static size_t | gen_int_hash (union HashKey key, size_t num_elems) |
| Generate a hash from an integer - Implements hash_gen_hash_t -.
|
|
Prototype for a Key hashing function.
- Parameters
-
key | Key to hash |
num_elems | Number of elements in the Hash Table |
Turn a Key (a string or an integer) into a hash id. The hash id will be a number between 0 and (num_elems-1).
◆ gen_string_hash()
static size_t gen_string_hash |
( |
union HashKey |
key, |
|
|
size_t |
num_elems |
|
) |
| |
|
static |
Generate a hash from a string - Implements hash_gen_hash_t -.
- Note
- If the key is NULL or empty, the retval will be 0
Definition at line 44 of file hash.c.
45{
46 size_t hash = 0;
47 const unsigned char *s = (
const unsigned char *) key.
strkey;
48 if (!s)
49 return 0;
50
51 while (*s != '\0')
52 hash += ((hash << 7) + *s++);
54
55 return hash;
56}
const char * strkey
String key.
◆ gen_case_string_hash()
static size_t gen_case_string_hash |
( |
union HashKey |
key, |
|
|
size_t |
num_elems |
|
) |
| |
|
static |
Generate a hash from a string (ignore the case) - Implements hash_gen_hash_t -.
- Note
- If the key is NULL or empty, the retval will be 0
Definition at line 71 of file hash.c.
72{
73 size_t hash = 0;
74 const unsigned char *s = (
const unsigned char *) key.
strkey;
75 if (!s)
76 return 0;
77
78 while (*s != '\0')
79 hash += ((hash << 7) + tolower(*s++));
81
82 return hash;
83}
◆ gen_int_hash()
static size_t gen_int_hash |
( |
union HashKey |
key, |
|
|
size_t |
num_elems |
|
) |
| |
|
static |
Generate a hash from an integer - Implements hash_gen_hash_t -.
Definition at line 96 of file hash.c.
97{
98 return (key.
intkey % num_elems);
99}
unsigned int intkey
Integer key.