]>
Commit | Line | Data |
---|---|---|
01fed0a8 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
01fed0a8 RB |
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 | */ | |
c2b67043 RB |
7 | #ifndef INCLUDE_oidmap_h__ |
8 | #define INCLUDE_oidmap_h__ | |
01fed0a8 RB |
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 | |
650e45f6 | 16 | #define kreallocarray git__reallocarray |
01fed0a8 RB |
17 | #define kfree git__free |
18 | #include "khash.h" | |
19 | ||
c8e02b87 | 20 | __KHASH_TYPE(oid, const git_oid *, void *) |
c2b67043 | 21 | typedef khash_t(oid) git_oidmap; |
01fed0a8 | 22 | |
78606263 | 23 | GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid) |
01fed0a8 | 24 | { |
5df18424 VM |
25 | khint_t h; |
26 | memcpy(&h, oid, sizeof(khint_t)); | |
01fed0a8 RB |
27 | return h; |
28 | } | |
29 | ||
c2b67043 | 30 | #define GIT__USE_OIDMAP \ |
78606263 | 31 | __KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) |
01fed0a8 | 32 | |
c2b67043 RB |
33 | #define git_oidmap_alloc() kh_init(oid) |
34 | #define git_oidmap_free(h) kh_destroy(oid,h), h = NULL | |
01fed0a8 | 35 | |
de1e81aa | 36 | #define git_oidmap_lookup_index(h, k) kh_get(oid, h, k) |
37 | #define git_oidmap_valid_index(h, idx) (idx != kh_end(h)) | |
38 | ||
39 | #define git_oidmap_value_at(h, idx) kh_val(h, idx) | |
40 | ||
41 | #define git_oidmap_insert(h, key, val, rval) do { \ | |
42 | khiter_t __pos = kh_put(oid, h, key, &rval); \ | |
43 | if (rval >= 0) { \ | |
44 | if (rval == 0) kh_key(h, __pos) = key; \ | |
45 | kh_val(h, __pos) = val; \ | |
46 | } } while (0) | |
47 | ||
48 | #define git_oidmap_foreach_value kh_foreach_value | |
3a728fb5 | 49 | |
50 | #define git_oidmap_size(h) kh_size(h) | |
51 | ||
01fed0a8 | 52 | #endif |