-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.h
More file actions
67 lines (46 loc) · 1.63 KB
/
hash.h
File metadata and controls
67 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Licensed under the MIT License by Bart Grantham, 2010. See ./LICENSE or
* http://www.opensource.org/licenses/mit-license.php
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __HASH_H_
#define __HASH_H_
/* string.h needed for strcspn() and strlen() */
#include <string.h>
/* stdio.h needed for printf() */
#include <stdio.h>
/* stdlib.h needed for malloc() and free() */
#include <stdlib.h>
#define HASH_KEYS_PER_TABLE 32
#define HASH_MAX_KEYSIZE 255
#define HASH_INITIAL_SALT 10000001
#define HASH_NEXT_MAGIC "\0__OUR_PRINCESS_IS_IN_ANOTHER_CASTLE__";
#define HASH_SELECT_FAILED NULL
#define HASH_INSERT_FAILED -2
#define HASH_INSERT -3
#define HASH_UPDATE -4
#define HASH_DELETE_FAILED NULL
typedef struct
{
char * key;
void * value; /* Could be another hash... */
} hash_entry;
#define hash_set(h, k, v) hash_set_depth(&(h), k, v, 0)
#define hash_get(h, k) hash_get_depth(h, k, 0)
#define hash_clear(h, k) hash_clear_depth(&(h), k, 0)
#define hash_dump(h) hash_dump_depth(h, 0)
int hash(const char * key, int salt);
void * hash_get_depth(hash_entry h[], const char * key, int depth);
int hash_set_depth(hash_entry * h[], const char * key, const void * value, int depth);
void * hash_clear_depth(hash_entry * h[], const char * key, int depth);
void hash_dump_depth(hash_entry h[], int depth);
inline int hash_entries(hash_entry h[]);
inline hash_entry * hash_first_entry(hash_entry h[]);
int hash_depth(hash_entry h[]);
void hash_stats(hash_entry h[], int * tables, int * entries, int * nulls, void ** max_ptr);
double hash_sparseness(hash_entry h[]);
#endif // __HASH_H_
#ifdef __cplusplus
}
#endif