1 #ifndef INCLUDE_hashtable_h__
2 #define INCLUDE_hashtable_h__
4 #include "git2/common.h"
9 #define GIT_HASHTABLE_HASHES 3
11 typedef uint32_t (*git_hash_ptr
)(const void *, int hash_id
);
12 typedef int (*git_hash_keyeq_ptr
)(const void *key_a
, const void *key_b
);
14 struct git_hashtable_node
{
19 struct git_hashtable
{
20 struct git_hashtable_node
*nodes
;
29 git_hash_keyeq_ptr key_equal
;
32 typedef struct git_hashtable_node git_hashtable_node
;
33 typedef struct git_hashtable git_hashtable
;
35 git_hashtable
*git_hashtable_alloc(size_t min_size
,
37 git_hash_keyeq_ptr key_eq
);
38 void *git_hashtable_lookup(git_hashtable
*h
, const void *key
);
39 int git_hashtable_remove(git_hashtable
*table
, const void *key
);
40 void git_hashtable_free(git_hashtable
*h
);
41 void git_hashtable_clear(git_hashtable
*h
);
42 int git_hashtable_merge(git_hashtable
*self
, git_hashtable
*other
);
44 int git_hashtable_insert2(git_hashtable
*h
, const void *key
, void *value
, void **old_value
);
46 GIT_INLINE(int) git_hashtable_insert(git_hashtable
*h
, const void *key
, void *value
)
49 return git_hashtable_insert2(h
, key
, value
, &_unused
);
52 #define git_hashtable_node_at(nodes, pos) ((git_hashtable_node *)(&nodes[pos]))
54 #define GIT_HASHTABLE_FOREACH(self, pkey, pvalue, code) {\
55 git_hashtable *_self = (self);\
56 git_hashtable_node *_nodes = _self->nodes;\
57 unsigned int _i, _size = _self->size;\
58 for (_i = 0; _i < _size; _i ++) {\
59 git_hashtable_node *_node = git_hashtable_node_at(_nodes, _i);\
63 pvalue = _node->value;\
69 #define GIT_HASHTABLE_FOREACH_DELETE() {\
70 _node->key = NULL; _node->value = NULL; _self->key_count--;\