aboutsummaryrefslogtreecommitdiff
path: root/oid-array.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-12-17 15:06:40 -0800
committerJunio C Hamano <gitster@pobox.com>2020-12-17 15:06:40 -0800
commite5ace7167a7d84cc906fd01768c470d75763a22d (patch)
treee7a203a787d80f3f107f93783de0342829e7ff2a /oid-array.h
parent21127fa9829da1f7b805e44517970194490567d0 (diff)
parent3361390cbedc962adcddcfd98676695c125fa180 (diff)
downloadgit-e5ace7167a7d84cc906fd01768c470d75763a22d.tar.xz
Merge branch 'jk/oid-array-cleanup'
Code clean-up. * jk/oid-array-cleanup: commit-graph: use size_t for array allocation and indexing commit-graph: replace packed_oid_list with oid_array commit-graph: drop count_distinct_commits() function oid-array: provide a for-loop iterator oid-array: make sort function public cache.h: move hash/oid functions to hash.h t0064: make duplicate tests more robust t0064: drop sha1 mention from filename oid-array.h: drop sha1 mention from header guard
Diffstat (limited to 'oid-array.h')
-rw-r--r--oid-array.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/oid-array.h b/oid-array.h
index f28d322c90..72bca78b7d 100644
--- a/oid-array.h
+++ b/oid-array.h
@@ -1,5 +1,7 @@
-#ifndef SHA1_ARRAY_H
-#define SHA1_ARRAY_H
+#ifndef OID_ARRAY_H
+#define OID_ARRAY_H
+
+#include "hash.h"
/**
* The API provides storage and manipulation of sets of object identifiers.
@@ -106,4 +108,30 @@ void oid_array_filter(struct oid_array *array,
for_each_oid_fn want,
void *cbdata);
-#endif /* SHA1_ARRAY_H */
+/**
+ * Sort the array in order of ascending object id.
+ */
+void oid_array_sort(struct oid_array *array);
+
+/**
+ * Find the next unique oid in the array after position "cur".
+ * The array must be sorted for this to work. You can iterate
+ * over unique elements like this:
+ *
+ * size_t i;
+ * oid_array_sort(array);
+ * for (i = 0; i < array->nr; i = oid_array_next_unique(array, i))
+ * printf("%s", oid_to_hex(array->oids[i]);
+ *
+ * Non-unique iteration can just increment with "i++" to visit each element.
+ */
+static inline size_t oid_array_next_unique(struct oid_array *array, size_t cur)
+{
+ do {
+ cur++;
+ } while (cur < array->nr &&
+ oideq(array->oid + cur, array->oid + cur - 1));
+ return cur;
+}
+
+#endif /* OID_ARRAY_H */