oidmap: add oidmap iterator methods
[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{
9e6fabde 6 if (!set->map.map.tablesize)
29c2bd5f 7 return 0;
9e6fabde 8 return !!oidmap_get(&set->map, oid);
29c2bd5f
JK
9}
10
11int oidset_insert(struct oidset *set, const struct object_id *oid)
12{
9e6fabde 13 struct oidmap_entry *entry;
29c2bd5f 14
9e6fabde
JT
15 if (!set->map.map.tablesize)
16 oidmap_init(&set->map, 0);
17 else if (oidset_contains(set, oid))
29c2bd5f
JK
18 return 1;
19
20 entry = xmalloc(sizeof(*entry));
29c2bd5f
JK
21 oidcpy(&entry->oid, oid);
22
9e6fabde 23 oidmap_put(&set->map, entry);
29c2bd5f
JK
24 return 0;
25}
26
27void oidset_clear(struct oidset *set)
28{
9e6fabde 29 oidmap_free(&set->map, 1);
29c2bd5f 30}