summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-12-06 16:36:42 -0800
committerOri Bernstein <ori@eigenstate.org>2016-12-06 16:36:42 -0800
commitd495c764a13dbc06ff3fbdd5254123b5125f4dd1 (patch)
treecffeb85a491f8b6be4cc163c0d677af4c33a140f
parent9a50dfed92787e84786453a3afc645c1b2610d96 (diff)
downloadmc-d495c764a13dbc06ff3fbdd5254123b5125f4dd1.tar.gz
Add htcount.
It's useful to know how many entries are in a hashtable.
-rw-r--r--lib/std/htab.myr5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/std/htab.myr b/lib/std/htab.myr
index ccccfe9..ec4ce72 100644
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -26,6 +26,7 @@ pkg std =
generic htgetv : (ht : htab(@k, @v)#, k : @k, fallback : @v-> @v)
generic hthas : (ht : htab(@k, @v)#, k : @k -> bool)
generic htkeys : (ht : htab(@k, @v)# -> @k[:])
+ generic htcount : (ht : htab(@k, @v)# -> std.size)
generic byhtkeyvals : (ht : htab(@k, @v)# -> htkviter(@k, @v))
impl iterable htkviter(@k, @v) -> (@k, @v)
@@ -207,6 +208,10 @@ generic htkeys = {ht
-> keys
}
+generic htcount = {ht
+ -> ht.nelt
+}
+
generic byhtkeyvals = {ht
-> [.ht = ht, .idx = 0]
}