make set compatible with non-strings, still very slow

This commit is contained in:
Sami Samhuri 2011-06-05 22:00:43 -07:00
parent d2b88f5c54
commit 92912c0678

View file

@ -42,7 +42,7 @@ Set.prototype.diff = function(other) {
var d = []
, x
;
for (x in this.members) if (!(x in other.members)) d.push(x);
for (x in this.members) if (!(x in other.members)) d.push(this.members[x]);
return new Set(d);
};
@ -58,9 +58,14 @@ Set.prototype.remove = function(item) {
};
Set.prototype.toArray = function() {
return Object.keys(this.members);
var ms = this.members;
return ownProps(this.members).map(function(k) { return ms[k]; });
};
Set.prototype.union = function(other) {
return new Set(ownProps(this.members).concat(ownProps(other.members)));
var ms = this.members;
, u = ownProps(this.members).map(function(k) { return ms[k]; });
ms = other.members;
u = u.concat(ownProps(ms).map(function(k) { return ms[k]; }));
return new Set(u);
};