oidset: introduce 'oidset_size'
Occasionally, it may be useful for callers to know the number of object IDs in an oidset. Right now, the only way to compute this is to call 'kh_size' on the internal 'kh_set_oid_t'. Similar to how we wrap other 'kh_*' functions over the 'oidset' type, let's allow callers to compute this value by introducing 'oidset_size'. We will add its first caller in the subsequent commit. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Apr 13, 2020 at 22:04 UTC
f4781068faafad5e10fb6e8ae312ebd5b0e7bb55
2 files changed
+10
oidset.c
+5
index f63ce818f6..15d4e18c37 100644
--- a/oidset.c
+++ b/oidset.c
@@ -36,6 +36,11 @@ void oidset_clear(struct oidset *set)
oidset_init(set, 0);
}
+int oidset_size(struct oidset *set)
+{
+ return kh_size(&set->set);
+}
+
void oidset_parse_file(struct oidset *set, const char *path)
{
FILE *fp;
oidset.h
+5
index 5346563b0b..80c3a347f9 100644
--- a/oidset.h
+++ b/oidset.h
@@ -55,6 +55,11 @@ int oidset_insert(struct oidset *set, const struct object_id *oid);
*/
int oidset_remove(struct oidset *set, const struct object_id *oid);
+/**
+ * Returns the number of oids in the set.
+ */
+int oidset_size(struct oidset *set);
+
/**
* Remove all entries from the oidset, freeing any resources associated with
* it.