hash-count

This commit is contained in:
Danny Yoo 2011-11-07 19:07:34 -05:00
parent c02c40f93e
commit 4c4d4437b8
6 changed files with 28 additions and 1 deletions

View File

@ -109,6 +109,7 @@
'hash-remove!
'hash-remove
'equal-hash-code
'hash-count
'string-copy
))

View File

@ -137,6 +137,10 @@
return new WhalesongHashtable(this.type, this.hash_function, this.equality_function, this.hash.clone());
};
WhalesongHashtable.prototype.size = function() {
return this.hash.size();
};
WhalesongHashtable.prototype.toWrittenString = function (cache) {
var keys = this.hash.keys();
var ret = [], i;
@ -251,6 +255,11 @@
this.map = map;
};
WhalesongImmutableHashtable.prototype.size = function() {
return this.map.items().length;
};
WhalesongImmutableHashtable.prototype.toWrittenString = function (cache) {
var items = this.map.items();
var ret = [], i;

View File

@ -2579,6 +2579,13 @@
return hash.clone();
});
installPrimitiveProcedure(
'hash-count',
1,
function(M) {
return checkHash(M, 'hash-count', 0).size();
});
installPrimitiveProcedure(
'hash',
baselib.arity.makeArityAtLeast(0),

View File

@ -168,6 +168,7 @@
hash-remove!
hash-remove
equal-hash-code
hash-count

View File

@ -55,3 +55,6 @@ true
A
alphabet
1
2

View File

@ -132,3 +132,9 @@
(hash-set! h2 'a "alphabet")
(displayln (hash-ref h1 'a))
(displayln (hash-ref h2 'a)))
(newline)
(hash-count (make-hash '((a . a))))
(hash-count (make-immutable-hash '((b . b)
(c . d))))