Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //implementation of state object
- //the state acts with a backbone of an unordered set
- //it references values via a stringifyed name of themselves, and allows them
- //to be retrieved in O(1) time
- var State = (function(){
- function State(){
- }
- //stores the element via string key of itself
- State.prototype.insert = function(elem){
- this[JSON.stringify(elem)] = elem;
- };
- //checks if element is in the state
- State.prototype.check = function(elem){
- return JSON.stringify(elem) in this;
- };
- State.prototype.del = function(elem){
- delete this[JSON.stringify(elem)];
- };
- return State;
- })();
- /* var a = new State();
- a
- => {}
- a.insert({foo:5})
- a
- => { '{"foo":5}': { foo: 5 } }
- a.check({foo:5})
- => true
- a.insert({foo:true})
- a.insert({foo:true})
- a
- => { '{"foo":5}': { foo: 5 }, '{"foo":true}': { foo: true } }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement