]>
git.proxmox.com Git - libgit2.git/blob - src/offmap.c
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(off
, off64_t
, void *)
19 __KHASH_IMPL(off
, static kh_inline
, off64_t
, void *, 1, kh_int64_hash_func
, kh_int64_hash_equal
)
22 int git_offmap_new(git_offmap
**out
)
25 GIT_ERROR_CHECK_ALLOC(*out
);
30 void git_offmap_free(git_offmap
*map
)
35 void git_offmap_clear(git_offmap
*map
)
40 size_t git_offmap_size(git_offmap
*map
)
45 void *git_offmap_get(git_offmap
*map
, const off64_t key
)
47 size_t idx
= kh_get(off
, map
, key
);
48 if (idx
== kh_end(map
) || !kh_exist(map
, idx
))
50 return kh_val(map
, idx
);
53 int git_offmap_set(git_offmap
*map
, const off64_t key
, void *value
)
58 idx
= kh_put(off
, map
, key
, &rval
);
63 kh_key(map
, idx
) = key
;
65 kh_val(map
, idx
) = value
;
70 int git_offmap_delete(git_offmap
*map
, const off64_t key
)
72 khiter_t idx
= kh_get(off
, map
, key
);
73 if (idx
== kh_end(map
))
75 kh_del(off
, map
, idx
);
79 int git_offmap_exists(git_offmap
*map
, const off64_t key
)
81 return kh_get(off
, map
, key
) != kh_end(map
);
84 int git_offmap_iterate(void **value
, git_offmap
*map
, size_t *iter
, off64_t
*key
)
88 while (i
< map
->n_buckets
&& !kh_exist(map
, i
))
91 if (i
>= map
->n_buckets
)
95 *key
= kh_key(map
, i
);
97 *value
= kh_value(map
, i
);