oidset: use khash
[git/git.git] / oidset.c
CommitLineData
29c2bd5f
JK
1#include "cache.h"
2#include "oidset.h"
3
29c2bd5f
JK
4int oidset_contains(const struct oidset *set, const struct object_id *oid)
5{
8b2f8cbc
RS
6 khiter_t pos = kh_get_oid(&set->set, *oid);
7 return pos != kh_end(&set->set);
29c2bd5f
JK
8}
9
10int oidset_insert(struct oidset *set, const struct object_id *oid)
11{
8b2f8cbc
RS
12 int added;
13 kh_put_oid(&set->set, *oid, &added);
14 return !added;
29c2bd5f
JK
15}
16
c3a9ad31
JH
17int oidset_remove(struct oidset *set, const struct object_id *oid)
18{
8b2f8cbc
RS
19 khiter_t pos = kh_get_oid(&set->set, *oid);
20 if (pos == kh_end(&set->set))
21 return 0;
22 kh_del_oid(&set->set, pos);
23 return 1;
c3a9ad31
JH
24}
25
29c2bd5f
JK
26void oidset_clear(struct oidset *set)
27{
8b2f8cbc
RS
28 kh_release_oid(&set->set);
29 oidset_init(set, 0);
29c2bd5f 30}