notes: avoid leaking duplicate entries
[gitweb.git] / khash.h
diff --git a/khash.h b/khash.h
index 532109c87f7ce190b5de3e341bafad880238ecad..af747a683fed88d9c69c5e2571150adc89cb886e 100644 (file)
--- a/khash.h
+++ b/khash.h
@@ -69,14 +69,14 @@ static const double __ac_HASH_UPPER = 0.77;
                khval_t *vals; \
        } kh_##name##_t;
 
-#define __KHASH_PROTOTYPES(name, khkey_t, khval_t)                                             \
-       extern kh_##name##_t *kh_init_##name(void);                                                     \
-       extern void kh_destroy_##name(kh_##name##_t *h);                                        \
-       extern void kh_clear_##name(kh_##name##_t *h);                                          \
-       extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key);      \
-       extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
-       extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
-       extern void kh_del_##name(kh_##name##_t *h, khint_t x);
+#define __KHASH_PROTOTYPES(name, khkey_t, khval_t)                             \
+       kh_##name##_t *kh_init_##name(void);                                            \
+       void kh_destroy_##name(kh_##name##_t *h);                                       \
+       void kh_clear_##name(kh_##name##_t *h);                                         \
+       khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
+       int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
+       khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
+       void kh_del_##name(kh_##name##_t *h, khint_t x);
 
 #define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
        SCOPE kh_##name##_t *kh_init_##name(void) {                                                     \
@@ -332,4 +332,22 @@ typedef kh_sha1_t khash_sha1;
 KHASH_INIT(sha1_pos, const unsigned char *, int, 1, sha1hash, __kh_oid_cmp)
 typedef kh_sha1_pos_t khash_sha1_pos;
 
+static inline unsigned int oid_hash(struct object_id oid)
+{
+       return sha1hash(oid.hash);
+}
+
+static inline int oid_equal(struct object_id a, struct object_id b)
+{
+       return oideq(&a, &b);
+}
+
+KHASH_INIT(oid, struct object_id, int, 0, oid_hash, oid_equal)
+
+KHASH_INIT(oid_map, struct object_id, void *, 1, oid_hash, oid_equal)
+typedef kh_oid_t khash_oid_map;
+
+KHASH_INIT(oid_pos, struct object_id, int, 1, oid_hash, oid_equal)
+typedef kh_oid_pos_t khash_oid_pos;
+
 #endif /* __AC_KHASH_H */