]> git.proxmox.com Git - libgit2.git/blob - src/oidmap.h
Merge pull request #2600 from libgit2/cmn/embed-ssh
[libgit2.git] / src / oidmap.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_oidmap_h__
8 #define INCLUDE_oidmap_h__
9
10 #include "common.h"
11 #include "git2/oid.h"
12
13 #define kmalloc git__malloc
14 #define kcalloc git__calloc
15 #define krealloc git__realloc
16 #define kfree git__free
17 #include "khash.h"
18
19 __KHASH_TYPE(oid, const git_oid *, void *);
20 typedef khash_t(oid) git_oidmap;
21
22 GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
23 {
24 khint_t h;
25 memcpy(&h, oid, sizeof(khint_t));
26 return h;
27 }
28
29 #define GIT__USE_OIDMAP \
30 __KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal)
31
32 #define git_oidmap_alloc() kh_init(oid)
33 #define git_oidmap_free(h) kh_destroy(oid,h), h = NULL
34
35 #define git_oidmap_lookup_index(h, k) kh_get(oid, h, k)
36 #define git_oidmap_valid_index(h, idx) (idx != kh_end(h))
37
38 #define git_oidmap_value_at(h, idx) kh_val(h, idx)
39
40 #define git_oidmap_insert(h, key, val, rval) do { \
41 khiter_t __pos = kh_put(oid, h, key, &rval); \
42 if (rval >= 0) { \
43 if (rval == 0) kh_key(h, __pos) = key; \
44 kh_val(h, __pos) = val; \
45 } } while (0)
46
47 #define git_oidmap_foreach_value kh_foreach_value
48
49 #define git_oidmap_size(h) kh_size(h)
50
51 #endif