shithub: mc

Download patch

ref: d495c764a13dbc06ff3fbdd5254123b5125f4dd1
parent: 9a50dfed92787e84786453a3afc645c1b2610d96
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Dec 6 11:36:42 EST 2016

Add htcount.

	It's useful to know how many entries are in a hashtable.

--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -26,6 +26,7 @@
 	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)
@@ -205,6 +206,10 @@
 		;;
 	;;
 	-> keys
+}
+
+generic htcount = {ht
+	-> ht.nelt
 }
 
 generic byhtkeyvals = {ht