1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 20:56:09 +02:00
git/oidset.c
Jonathan Tan 9e6fabde82 oidmap: map with OID as key
This is similar to using the hashmap in hashmap.c, but with an
easier-to-use API. In particular, custom entry comparisons no longer
need to be written, and lookups can be done without constructing a
temporary entry structure.

This is implemented as a thin wrapper over the hashmap API. In
particular, this means that there is an additional 4-byte overhead due
to the fact that the first 4 bytes of the hash is redundantly stored.
For now, I'm taking the simpler approach, but if need be, we can
reimplement oidmap without affecting the callers significantly.

oidset has been updated to use oidmap.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-01 17:18:03 +09:00

31 lines
585 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;
}
void oidset_clear(struct oidset *set)
{
oidmap_free(&set->map, 1);
}