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