2017-02-08 20:53:07 +00:00
|
|
|
#include "cache.h"
|
|
|
|
#include "oidset.h"
|
|
|
|
|
|
|
|
int oidset_contains(const struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2017-09-29 22:54:22 +00:00
|
|
|
if (!set->map.map.tablesize)
|
2017-02-08 20:53:07 +00:00
|
|
|
return 0;
|
2017-09-29 22:54:22 +00:00
|
|
|
return !!oidmap_get(&set->map, oid);
|
2017-02-08 20:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int oidset_insert(struct oidset *set, const struct object_id *oid)
|
|
|
|
{
|
2017-09-29 22:54:22 +00:00
|
|
|
struct oidmap_entry *entry;
|
2017-02-08 20:53:07 +00:00
|
|
|
|
2017-09-29 22:54:22 +00:00
|
|
|
if (!set->map.map.tablesize)
|
|
|
|
oidmap_init(&set->map, 0);
|
|
|
|
else if (oidset_contains(set, oid))
|
2017-02-08 20:53:07 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
entry = xmalloc(sizeof(*entry));
|
|
|
|
oidcpy(&entry->oid, oid);
|
|
|
|
|
2017-09-29 22:54:22 +00:00
|
|
|
oidmap_put(&set->map, entry);
|
2017-02-08 20:53:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:58:49 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-08 20:53:07 +00:00
|
|
|
void oidset_clear(struct oidset *set)
|
|
|
|
{
|
2017-09-29 22:54:22 +00:00
|
|
|
oidmap_free(&set->map, 1);
|
2017-02-08 20:53:07 +00:00
|
|
|
}
|