2017-02-08 23:53:07 +03:00
|
|
|
#include "cache.h"
|
|
|
|
#include "oidset.h"
|
|
|
|
|
2018-10-04 18:14:37 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-08 23:53:07 +03:00
|
|
|
int oidset_contains(const struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2018-10-04 18:13:06 +03:00
|
|
|
khiter_t pos = kh_get_oid(&set->set, *oid);
|
|
|
|
return pos != kh_end(&set->set);
|
2017-02-08 23:53:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int oidset_insert(struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2018-10-04 18:13:06 +03:00
|
|
|
int added;
|
|
|
|
kh_put_oid(&set->set, *oid, &added);
|
|
|
|
return !added;
|
2017-02-08 23:53:07 +03:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:58:49 +03:00
|
|
|
int oidset_remove(struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2018-10-04 18:13:06 +03:00
|
|
|
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;
|
2017-11-21 23:58:49 +03:00
|
|
|
}
|
|
|
|
|
2017-02-08 23:53:07 +03:00
|
|
|
void oidset_clear(struct oidset *set)
|
|
|
|
{
|
2018-10-04 18:13:06 +03:00
|
|
|
kh_release_oid(&set->set);
|
|
|
|
oidset_init(set, 0);
|
2017-02-08 23:53:07 +03:00
|
|
|
}
|