]>
Commit | Line | Data |
---|---|---|
29c2bd5f JK |
1 | #include "cache.h" |
2 | #include "oidset.h" | |
3 | ||
8c84ae65 RS |
4 | void oidset_init(struct oidset *set, size_t initial_size) |
5 | { | |
6 | memset(&set->set, 0, sizeof(set->set)); | |
7 | if (initial_size) | |
8 | kh_resize_oid(&set->set, initial_size); | |
9 | } | |
10 | ||
29c2bd5f JK |
11 | int oidset_contains(const struct oidset *set, const struct object_id *oid) |
12 | { | |
8b2f8cbc RS |
13 | khiter_t pos = kh_get_oid(&set->set, *oid); |
14 | return pos != kh_end(&set->set); | |
29c2bd5f JK |
15 | } |
16 | ||
17 | int oidset_insert(struct oidset *set, const struct object_id *oid) | |
18 | { | |
8b2f8cbc RS |
19 | int added; |
20 | kh_put_oid(&set->set, *oid, &added); | |
21 | return !added; | |
29c2bd5f JK |
22 | } |
23 | ||
c3a9ad31 JH |
24 | int oidset_remove(struct oidset *set, const struct object_id *oid) |
25 | { | |
8b2f8cbc RS |
26 | khiter_t pos = kh_get_oid(&set->set, *oid); |
27 | if (pos == kh_end(&set->set)) | |
28 | return 0; | |
29 | kh_del_oid(&set->set, pos); | |
30 | return 1; | |
c3a9ad31 JH |
31 | } |
32 | ||
29c2bd5f JK |
33 | void oidset_clear(struct oidset *set) |
34 | { | |
8b2f8cbc RS |
35 | kh_release_oid(&set->set); |
36 | oidset_init(set, 0); | |
29c2bd5f | 37 | } |