More actions
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
function PrimitiveSet() {
this.data = {};
this.counter = 0;
}
PrimitiveSet.prototype.add = function(val) {
if (!this.data.hasOwnProperty(val)) {
this.data[val] = this.counter;
this.counter++;
}
};
PrimitiveSet.prototype.clear = function() {
this.data = {};
this.counter = 0;
};
PrimitiveSet.prototype.delete = function( val ) {
delete this.data[val];
};
PrimitiveSet.prototype.has = function( val ) {
return val in this.data;
};
PrimitiveSet.prototype.values = function() {
var key_vals = [];
for (var key in this.data) {
key_vals.push( { key: key, value: this.data[key] } );
}
key_vals.sort( function( left, right ) {
return left.value - right.value;
} );
return key_vals.map( function( key_val ) {
return key_val.key;
} );
};
Object.preventExtensions(PrimitiveSet.prototype);
window.pswiki.polyfill = {
PrimitiveSet: PrimitiveSet,
};