1 #include "git-compat-util.h"
4 #include "hash-lookup.h"
6 void oid_array_append(struct oid_array
*array
, const struct object_id
*oid
)
8 ALLOC_GROW(array
->oid
, array
->nr
+ 1, array
->alloc
);
9 oidcpy(&array
->oid
[array
->nr
++], oid
);
13 static int void_hashcmp(const void *a
, const void *b
)
18 void oid_array_sort(struct oid_array
*array
)
22 QSORT(array
->oid
, array
->nr
, void_hashcmp
);
26 static const struct object_id
*oid_access(size_t index
, const void *table
)
28 const struct object_id
*array
= table
;
32 int oid_array_lookup(struct oid_array
*array
, const struct object_id
*oid
)
34 oid_array_sort(array
);
35 return oid_pos(oid
, array
->oid
, array
->nr
, oid_access
);
38 void oid_array_clear(struct oid_array
*array
)
40 FREE_AND_NULL(array
->oid
);
47 int oid_array_for_each(struct oid_array
*array
,
53 /* No oid_array_sort() here! See oid-array.h */
55 for (i
= 0; i
< array
->nr
; i
++) {
56 int ret
= fn(array
->oid
+ i
, data
);
63 int oid_array_for_each_unique(struct oid_array
*array
,
69 oid_array_sort(array
);
71 for (i
= 0; i
< array
->nr
; i
= oid_array_next_unique(array
, i
)) {
72 int ret
= fn(array
->oid
+ i
, data
);
79 void oid_array_filter(struct oid_array
*array
,
83 size_t nr
= array
->nr
, src
, dst
;
84 struct object_id
*oids
= array
->oid
;
86 for (src
= dst
= 0; src
< nr
; src
++) {
87 if (want(&oids
[src
], cb_data
)) {
89 oidcpy(&oids
[dst
], &oids
[src
]);