fsmonitor: MINGW support for watchman integration
[git/raj.git] / oidset.c
bloba6a08ba52abdcda75b0bd5cc28349cd3c4be871c
1 #include "cache.h"
2 #include "oidset.h"
4 struct oidset_entry {
5 struct hashmap_entry hash;
6 struct object_id oid;
7 };
9 static int oidset_hashcmp(const void *unused_cmp_data,
10 const void *va, const void *vb,
11 const void *vkey)
13 const struct oidset_entry *a = va, *b = vb;
14 const struct object_id *key = vkey;
15 return oidcmp(&a->oid, key ? key : &b->oid);
18 int oidset_contains(const struct oidset *set, const struct object_id *oid)
20 struct hashmap_entry key;
22 if (!set->map.cmpfn)
23 return 0;
25 hashmap_entry_init(&key, sha1hash(oid->hash));
26 return !!hashmap_get(&set->map, &key, oid);
29 int oidset_insert(struct oidset *set, const struct object_id *oid)
31 struct oidset_entry *entry;
33 if (!set->map.cmpfn)
34 hashmap_init(&set->map, oidset_hashcmp, NULL, 0);
36 if (oidset_contains(set, oid))
37 return 1;
39 entry = xmalloc(sizeof(*entry));
40 hashmap_entry_init(&entry->hash, sha1hash(oid->hash));
41 oidcpy(&entry->oid, oid);
43 hashmap_add(&set->map, entry);
44 return 0;
47 void oidset_clear(struct oidset *set)
49 hashmap_free(&set->map, 1);