]>
git.proxmox.com Git - libgit2.git/blob - src/oidmap.c
0ae8bf33ea5504a4146e6793bfb521b956dcbf11
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
10 #define kmalloc git__malloc
11 #define kcalloc git__calloc
12 #define krealloc git__realloc
13 #define kreallocarray git__reallocarray
14 #define kfree git__free
17 __KHASH_TYPE(oid
, const git_oid
*, void *)
19 GIT_INLINE(khint_t
) git_oidmap_hash(const git_oid
*oid
)
22 memcpy(&h
, oid
, sizeof(khint_t
));
26 __KHASH_IMPL(oid
, static kh_inline
, const git_oid
*, void *, 1, git_oidmap_hash
, git_oid_equal
)
28 int git_oidmap_new(git_oidmap
**out
)
31 GIT_ERROR_CHECK_ALLOC(*out
);
36 void git_oidmap_free(git_oidmap
*map
)
41 void git_oidmap_clear(git_oidmap
*map
)
46 size_t git_oidmap_size(git_oidmap
*map
)
51 void *git_oidmap_get(git_oidmap
*map
, const git_oid
*key
)
53 size_t idx
= kh_get(oid
, map
, key
);
54 if (idx
== kh_end(map
) || !kh_exist(map
, idx
))
56 return kh_val(map
, idx
);
59 int git_oidmap_set(git_oidmap
*map
, const git_oid
*key
, void *value
)
64 idx
= kh_put(oid
, map
, key
, &rval
);
69 kh_key(map
, idx
) = key
;
71 kh_val(map
, idx
) = value
;
76 int git_oidmap_delete(git_oidmap
*map
, const git_oid
*key
)
78 khiter_t idx
= kh_get(oid
, map
, key
);
79 if (idx
== kh_end(map
))
81 kh_del(oid
, map
, idx
);
85 int git_oidmap_exists(git_oidmap
*map
, const git_oid
*key
)
87 return kh_get(oid
, map
, key
) != kh_end(map
);
90 int git_oidmap_iterate(void **value
, git_oidmap
*map
, size_t *iter
, const git_oid
**key
)
94 while (i
< map
->n_buckets
&& !kh_exist(map
, i
))
97 if (i
>= map
->n_buckets
)
101 *key
= kh_key(map
, i
);
103 *value
= kh_value(map
, i
);