1 #include "git-compat-util.h"
3 #include "hash-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
);
10 oid_set_algo(&array
->oid
[array
->nr
- 1], the_hash_algo
);
14 static int void_hashcmp(const void *va
, const void *vb
)
16 const struct object_id
*a
= va
, *b
= vb
;
18 if (a
->algo
== b
->algo
)
21 ret
= a
->algo
> b
->algo
? 1 : -1;
25 void oid_array_sort(struct oid_array
*array
)
29 QSORT(array
->oid
, array
->nr
, void_hashcmp
);
33 static const struct object_id
*oid_access(size_t index
, const void *table
)
35 const struct object_id
*array
= table
;
39 int oid_array_lookup(struct oid_array
*array
, const struct object_id
*oid
)
41 oid_array_sort(array
);
42 return oid_pos(oid
, array
->oid
, array
->nr
, oid_access
);
45 void oid_array_clear(struct oid_array
*array
)
47 FREE_AND_NULL(array
->oid
);
54 int oid_array_for_each(struct oid_array
*array
,
60 /* No oid_array_sort() here! See oid-array.h */
62 for (i
= 0; i
< array
->nr
; i
++) {
63 int ret
= fn(array
->oid
+ i
, data
);
70 int oid_array_for_each_unique(struct oid_array
*array
,
76 oid_array_sort(array
);
78 for (i
= 0; i
< array
->nr
; i
= oid_array_next_unique(array
, i
)) {
79 int ret
= fn(array
->oid
+ i
, data
);
86 void oid_array_filter(struct oid_array
*array
,
90 size_t nr
= array
->nr
, src
, dst
;
91 struct object_id
*oids
= array
->oid
;
93 for (src
= dst
= 0; src
< nr
; src
++) {
94 if (want(&oids
[src
], cb_data
)) {
96 oidcpy(&oids
[dst
], &oids
[src
]);