diff options
author | Daniel Hartwig <mandyke@gmail.com> | 2013-02-17 16:38:31 +0800 |
---|---|---|
committer | Daniel Hartwig <mandyke@gmail.com> | 2013-02-18 10:21:43 +0800 |
commit | 3330f00f54649cdd0914b6ff03c7b7bbc38ffa8d (patch) | |
tree | 300aa688b6c2a940e0cfdf05f7829321709288dd /test-suite | |
parent | 3d2b2676e3fc0a5b243b8a4188d07bba1b4b40a4 (diff) | |
download | guile-3330f00f54649cdd0914b6ff03c7b7bbc38ffa8d.tar.gz |
add hash-count for native tables
* libguile/hashtab.c (scm_hash_count): New function. Count the number
of elements in a hash table.
* doc/ref/api-compound.texi (Hash Tables): Update examples and
reference.
* test-suite/tests/hash.test (hash-count): New test.
Diffstat (limited to 'test-suite')
-rw-r--r-- | test-suite/tests/hash.test | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test-suite/tests/hash.test b/test-suite/tests/hash.test index bcdfe9110..72aa0c478 100644 --- a/test-suite/tests/hash.test +++ b/test-suite/tests/hash.test @@ -292,3 +292,19 @@ exception:wrong-type-arg (hashx-set! (lambda (k s) 1) (lambda (k al) #t) (make-hash-table) 'foo 'bar)) ) + + +;;; +;;; hash-count +;;; + +(with-test-prefix "hash-count" + (let ((table (make-hash-table))) + (hashq-set! table 'foo "bar") + (hashq-set! table 'braz "zonk") + (hashq-create-handle! table 'frob #f) + + (pass-if (equal? 3 (hash-count (const #t) table))) + + (pass-if (equal? 2 (hash-count (lambda (k v) + (string? v)) table))))) |