git/oidset.c
Jeff Hostetler c3a9ad3117 oidset: add iterator methods to oidset
Add the usual iterator methods to oidset.
Add oidset_remove().

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-11-22 14:11:56 +09:00

41 lines
767 B
C

#include "cache.h"
#include "oidset.h"
int oidset_contains(const struct oidset *set, const struct object_id *oid)
{
if (!set->map.map.tablesize)
return 0;
return !!oidmap_get(&set->map, oid);
}
int oidset_insert(struct oidset *set, const struct object_id *oid)
{
struct oidmap_entry *entry;
if (!set->map.map.tablesize)
oidmap_init(&set->map, 0);
else if (oidset_contains(set, oid))
return 1;
entry = xmalloc(sizeof(*entry));
oidcpy(&entry->oid, oid);
oidmap_put(&set->map, entry);
return 0;
}
int oidset_remove(struct oidset *set, const struct object_id *oid)
{
struct oidmap_entry *entry;
entry = oidmap_remove(&set->map, oid);
free(entry);
return (entry != NULL);
}
void oidset_clear(struct oidset *set)
{
oidmap_free(&set->map, 1);
}