NeoMutt  2024-04-25-97-g7d2481
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Hash Generator API

Prototype for a Key hashing function. More...

Functions

static size_t gen_hash_string (union HashKey key, size_t num_elems)
 Generate a hash from a string - Implements hash_gen_hash_t -.
 
static size_t gen_hash_case_string (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_hash_int (union HashKey key, size_t num_elems)
 Generate a hash from an integer - Implements hash_gen_hash_t -.
 

Detailed Description

Prototype for a Key hashing function.

Parameters
keyKey to hash
num_elemsNumber 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).

Function Documentation

◆ gen_hash_string()

static size_t gen_hash_string ( 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++);
53 hash = (hash * SOME_PRIME) % num_elems;
54
55 return hash;
56}
#define SOME_PRIME
Definition: hash.c:37
const char * strkey
String key.
Definition: hash.h:35
+ Here is the caller graph for this function:

◆ gen_hash_case_string()

static size_t gen_hash_case_string ( 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++));
80 hash = (hash * SOME_PRIME) % num_elems;
81
82 return hash;
83}
+ Here is the caller graph for this function:

◆ gen_hash_int()

static size_t gen_hash_int ( 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.
Definition: hash.h:36
+ Here is the caller graph for this function: