oidset.c 794 Bytes
Newer Older
Jeff King's avatar
Jeff King committed
1 2 3
#include "cache.h"
#include "oidset.h"

4 5 6 7 8 9 10
void oidset_init(struct oidset *set, size_t initial_size)
{
	memset(&set->set, 0, sizeof(set->set));
	if (initial_size)
		kh_resize_oid(&set->set, initial_size);
}

Jeff King's avatar
Jeff King committed
11 12
int oidset_contains(const struct oidset *set, const struct object_id *oid)
{
René Scharfe's avatar
René Scharfe committed
13 14
	khiter_t pos = kh_get_oid(&set->set, *oid);
	return pos != kh_end(&set->set);
Jeff King's avatar
Jeff King committed
15 16 17 18
}

int oidset_insert(struct oidset *set, const struct object_id *oid)
{
René Scharfe's avatar
René Scharfe committed
19 20 21
	int added;
	kh_put_oid(&set->set, *oid, &added);
	return !added;
Jeff King's avatar
Jeff King committed
22 23
}

24 25
int oidset_remove(struct oidset *set, const struct object_id *oid)
{
René Scharfe's avatar
René Scharfe committed
26 27 28 29 30
	khiter_t pos = kh_get_oid(&set->set, *oid);
	if (pos == kh_end(&set->set))
		return 0;
	kh_del_oid(&set->set, pos);
	return 1;
31 32
}

Jeff King's avatar
Jeff King committed
33 34
void oidset_clear(struct oidset *set)
{
René Scharfe's avatar
René Scharfe committed
35 36
	kh_release_oid(&set->set);
	oidset_init(set, 0);
Jeff King's avatar
Jeff King committed
37
}