hash-keys and hash-values

This commit is contained in:
Danny Yoo 2011-11-09 11:18:12 -05:00
parent 544cab5f17
commit 588ff1644b
5 changed files with 46 additions and 1 deletions

View File

@ -111,6 +111,8 @@
'hash-remove
'equal-hash-code
'hash-count
'hash-keys
'hash-values
'string-copy
))

View File

@ -163,6 +163,15 @@
return ('#' + this.type + '(' + ret.join(' ') + ')');
};
WhalesongHashtable.prototype.keys = function() {
return this.hash.keys();
};
WhalesongHashtable.prototype.values = function() {
return this.hash.values();
};
WhalesongHashtable.prototype.equals = function (other, aUnionFind) {
if (!(other instanceof WhalesongHashtable)) {
return false;
@ -282,6 +291,14 @@
return ('#' + this.type + '(' + ret.join(' ') + ')');
};
WhalesongImmutableHashtable.prototype.keys = function() {
return this.map.keys();
};
WhalesongImmutableHashtable.prototype.values = function() {
return this.map.values();
};
WhalesongImmutableHashtable.prototype.equals = function (other, aUnionFind) {
if (!(other instanceof WhalesongImmutableHashtable)) {
return false;

View File

@ -238,6 +238,15 @@
};
var arrayToList = function (arr) {
var result = EMPTY, i;
for (i = arr.length -1; i >= 0; i--) {
result = makePair(arr[i], result);
}
return result;
};
// Coerse a list back into a JavaScript array.
var listToArray = function (lst) {
var result = [];
@ -311,5 +320,6 @@
exports.length = length;
exports.listRef = listRef;
exports.listToArray = listToArray;
exports.arrayToList = arrayToList;
}(this.plt.baselib));

View File

@ -2767,6 +2767,21 @@
return hash.functionalRemove(key);
});
installPrimitiveProcedure(
'hash-keys',
1,
function(M) {
var hash = checkHash(M, 'hash-keys', 0);
return baselib.lists.arrayToList(hash.keys());
});
installPrimitiveProcedure(
'hash-values',
1,
function(M) {
var hash = checkHash(M, 'hash-keys', 0);
return baselib.lists.arrayToList(hash.values());
});
installPrimitiveProcedure(
'hash-has-key?',

View File

@ -170,7 +170,8 @@
hash-remove
equal-hash-code
hash-count
hash-keys
hash-values
;; Kernel inlinable