Created
March 5, 2013 21:58
-
-
Save eduardolundgren/5094715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var HashSet = function() { | |
this.initializer(); | |
}; | |
HashSet.PRESENT = {}; | |
HashSet.prototype = { | |
_map: null, | |
initializer: function() { | |
var instance = this; | |
A.EventTarget.call(this, {emitFacade:true}); | |
instance._map = new A.Map(); | |
instance.publish({ | |
add: { defaultFn: instance._defAddFn }, | |
clear: { defaultFn: instance._defClearFn }, | |
remove: { defaultFn: instance._defRemoveFn } | |
}); | |
}, | |
add: function(value) { | |
this.fire('add', { value: value }); | |
}, | |
clear: function() { | |
this.fire('clear'); | |
}, | |
has: function(value) { | |
return this._map.has(value); | |
}, | |
isEmpty: function() { | |
return this._map.isEmpty(); | |
}, | |
remove: function(value) { | |
this.fire('remove', { value: value }); | |
}, | |
size: function() { | |
return this._map.size(); | |
}, | |
values: function() { | |
return this._map.keys(); | |
}, | |
_defAddFn: function(event) { | |
this._map.put(event.value, HashSet.PRESENT); | |
}, | |
_defClearFn: function() { | |
this._map.clear(); | |
}, | |
_defRemoveFn: function(event) { | |
var instance = this, | |
map = instance._map, | |
value = map.remove(event.value); | |
event.removed = (value === HashSet.PRESENT); | |
} | |
}; | |
A.Set = HashSet; | |
A.augment(A.Set, A.EventTarget); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment