3 #include "sha1-lookup.h"
5 void oid_array_append(struct oid_array *array, const struct object_id *oid)
7 ALLOC_GROW(array->oid, array->nr + 1, array->alloc);
8 oidcpy(&array->oid[array->nr++], oid);
12 static int void_hashcmp(const void *a, const void *b)
17 void oid_array_sort(struct oid_array *array)
21 QSORT(array->oid, array->nr, void_hashcmp);
25 static const unsigned char *sha1_access(size_t index, void *table)
27 struct object_id *array = table;
28 return array[index].hash;
31 int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
33 oid_array_sort(array);
34 return sha1_pos(oid->hash, array->oid, array->nr, sha1_access);
37 void oid_array_clear(struct oid_array *array)
39 FREE_AND_NULL(array->oid);
46 int oid_array_for_each(struct oid_array *array,
52 /* No oid_array_sort() here! See oid-array.h */
54 for (i = 0; i < array->nr; i++) {
55 int ret = fn(array->oid + i, data);
62 int oid_array_for_each_unique(struct oid_array *array,
68 oid_array_sort(array);
70 for (i = 0; i < array->nr; i = oid_array_next_unique(array, i)) {
71 int ret = fn(array->oid + i, data);
78 void oid_array_filter(struct oid_array *array,
82 size_t nr = array->nr, src, dst;
83 struct object_id *oids = array->oid;
85 for (src = dst = 0; src < nr; src++) {
86 if (want(&oids[src], cb_data)) {
88 oidcpy(&oids[dst], &oids[src]);