forked from felix021/pyshmht
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hashtable.h
47 lines (36 loc) · 1.08 KB
/
hashtable.h
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
#ifndef __HASH_TABLE__
#define __HASH_TABLE__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#define ALLOC(type, n) ((type *)malloc(sizeof(type) * n))
typedef struct __hashtable {
unsigned magic;
size_t ref_cnt, orig_capacity, capacity, size, flag_offset, bucket_offset;
} hashtable;
typedef unsigned u_int32;
typedef struct _ht_str {
u_int32 size;
char str[1];
} ht_str;
typedef struct _ht_iter {
hashtable *ht;
size_t pos;
ht_str *key, *value;
} ht_iter;
typedef int BOOL;
#define True 1
#define False 0
ht_iter* ht_get_iterator(hashtable *ht);
int ht_iter_next(ht_iter* iter);
size_t ht_memory_size(size_t capacity);
hashtable* ht_init(void *base_addr, size_t capacity, int force_init);
ht_str* ht_get(hashtable *ht, const char *key, u_int32 key_size);
int ht_set(hashtable *ht, const char *key, u_int32 key_size, const char *value, u_int32 value_size);
int ht_remove(hashtable *ht, const char *key, u_int32 key_size);
int ht_destroy(hashtable *ht);
int ht_is_valid(hashtable *ht);
#endif