NeoMutt  2025-12-11-769-g906513
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 46 of file hash.c.

47{
48 size_t hash = 0;
49 const unsigned char *s = (const unsigned char *) key.strkey;
50 if (!s)
51 return 0;
52
53 while (*s != '\0')
54 hash += ((hash << 7) + *s++);
55 hash = (hash * SOME_PRIME) % num_elems;
56
57 return hash;
58}
#define SOME_PRIME
A prime number used for hashing.
Definition hash.c:39
const char * strkey
String key.
Definition hash.h:36
+ 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 73 of file hash.c.

74{
75 size_t hash = 0;
76 const unsigned char *s = (const unsigned char *) key.strkey;
77 if (!s)
78 return 0;
79
80 while (*s != '\0')
81 hash += ((hash << 7) + mutt_tolower(*s++));
82 hash = (hash * SOME_PRIME) % num_elems;
83
84 return hash;
85}
int mutt_tolower(int arg)
Wrapper for tolower(3)
Definition ctype.c:126
+ Here is the call graph for this function:
+ 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 98 of file hash.c.

99{
100 return (key.intkey % num_elems);
101}
unsigned int intkey
Integer key.
Definition hash.h:37
+ Here is the caller graph for this function: