-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.h
More file actions
49 lines (36 loc) · 894 Bytes
/
hash.h
File metadata and controls
49 lines (36 loc) · 894 Bytes
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
#ifndef HASH_H
#define HASH_H
#include <stdint.h>
#include <stdbool.h>
typedef struct kv kv_t;
typedef struct umap umap_t;
struct kv {
char *k;
void *v;
kv_t *next;
};
kv_t *new_kv(
char * /* k */,
void * /* v */);
/* if called on a head,
frees the entire chain */
void free_kv(kv_t * /* r */);
struct umap {
uint64_t size;
kv_t **table;
/* non static methods */
bool (*push)(umap_t *, kv_t *);
void *(*find)(umap_t *, const char *);
/* static methods */
uint64_t (*hash)(const uint8_t *);
};
umap_t *new_umap(
uint64_t /* size */,
uint64_t (* /* hash */ )(const uint8_t *));
void free_umap(umap_t * /* mp */);
/* hash functions for string
refer to http://www.cse.yorku.ca/~oz/hash.html */
uint64_t djb2(const uint8_t * /* str */);
uint64_t sdbm(const uint8_t * /* str */);
uint64_t loselose(const uint8_t * /* str */);
#endif