]>
git.proxmox.com Git - libgit2.git/blob - src/oidmap.c
c42e5c25af5e097048ba81a7b68176d3fcf41263
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 git_oidmap
*git_oidmap_alloc()
33 void git_oidmap_free(git_oidmap
*map
)
38 void git_oidmap_clear(git_oidmap
*map
)
43 size_t git_oidmap_size(git_oidmap
*map
)
48 size_t git_oidmap_lookup_index(git_oidmap
*map
, const git_oid
*key
)
50 return kh_get(oid
, map
, key
);
53 int git_oidmap_valid_index(git_oidmap
*map
, size_t idx
)
55 return idx
!= kh_end(map
);
58 int git_oidmap_exists(git_oidmap
*map
, const git_oid
*key
)
60 return kh_get(oid
, map
, key
) != kh_end(map
);
63 int git_oidmap_has_data(git_oidmap
*map
, size_t idx
)
65 return kh_exist(map
, idx
);
68 const git_oid
*git_oidmap_key(git_oidmap
*map
, size_t idx
)
70 return kh_key(map
, idx
);
73 void git_oidmap_set_key_at(git_oidmap
*map
, size_t idx
, git_oid
*key
)
75 kh_key(map
, idx
) = key
;
78 void *git_oidmap_value_at(git_oidmap
*map
, size_t idx
)
80 return kh_val(map
, idx
);
83 void git_oidmap_set_value_at(git_oidmap
*map
, size_t idx
, void *value
)
85 kh_val(map
, idx
) = value
;
88 void git_oidmap_delete_at(git_oidmap
*map
, size_t idx
)
90 kh_del(oid
, map
, idx
);
93 int git_oidmap_put(git_oidmap
*map
, const git_oid
*key
, int *err
)
95 return kh_put(oid
, map
, key
, err
);
98 void git_oidmap_insert(git_oidmap
*map
, const git_oid
*key
, void *value
, int *rval
)
100 khiter_t idx
= kh_put(oid
, map
, key
, rval
);
104 kh_key(map
, idx
) = key
;
105 kh_val(map
, idx
) = value
;
109 void git_oidmap_delete(git_oidmap
*map
, const git_oid
*key
)
111 khiter_t idx
= git_oidmap_lookup_index(map
, key
);
112 if (git_oidmap_valid_index(map
, idx
))
113 git_oidmap_delete_at(map
, idx
);
116 size_t git_oidmap_begin(git_oidmap
*map
)
122 size_t git_oidmap_end(git_oidmap
*map
)
124 return map
->n_buckets
;