-
Notifications
You must be signed in to change notification settings - Fork 4
/
hash.h
59 lines (50 loc) · 1.95 KB
/
hash.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
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef __HASH__
#define __HASH__
#include <wchar.h>
#include <t_gc.h>
#include "types.h"
#define HASH_INIT_BUCKET (8)
struct hash_bucket {
wchar_t *key;
unsigned int index;
struct _toy_type *item;
struct hash_bucket *next;
};
typedef struct _hash {
int bucket_size;
struct hash_bucket *bucket;
int items;
int synonyms;
} Hash;
unsigned int hash_string_key(const wchar_t *key);
Hash* new_hash();
void hash_clear(Hash* h);
Hash* hash_set(Hash *hash, const wchar_t *key, const struct _toy_type *item);
Hash* hash_set_t(Hash *hash, const struct _toy_type *key, const struct _toy_type *item);
struct _toy_type* hash_get(Hash *hash, const wchar_t *key);
struct _toy_type* hash_get_t(Hash *hash, const struct _toy_type *key);
struct _toy_type* hash_get_and_unset(Hash *hash, const wchar_t *key);
struct _toy_type* hash_get_and_unset_t(Hash *hash, const struct _toy_type *key);
int hash_is_exists(Hash *hash, const wchar_t *key);
int hash_is_exists_t(Hash *hash, const struct _toy_type *key);
int hash_link(Hash *hash, const wchar_t *key,
Hash *to_hash, const wchar_t *to_key);
int hash_link_t(Hash *hash, const struct _toy_type *key,
Hash *to_hash, const struct _toy_type *to_key);
struct _toy_type* hash_get_keys(Hash *hash);
struct _toy_type* hash_get_keys_str(Hash *hash);
struct _toy_type* hash_get_pairs(Hash *hash);
struct _toy_type* hash_get_pairs_str(Hash *hash);
void hash_debug_dump(Hash *hash);
/* for search object method cache */
struct _toy_type* hash_get_method_cache(Hash* hash,
const struct _toy_type *object,
const struct _toy_type *key);
Hash* hash_set_method_cache(Hash* hash,
const struct _toy_type *object,
const struct _toy_type *key,
struct _toy_type *method);
#define hash_get_length(x) ((x==NULL)?0:x->items)
#define hash_get_synonyms(x) ((x==NULL)?0:x->synonyms)
#define hash_get_bucketsize(x) ((x==NULL)?0:x->bucket_size)
#endif /* __HASH__ */