vennmap
v0.0.10
Published
Javascript collection that allows objects to be retrieved using any arbitary combination of keys.
Downloads
2
Readme
VennMap
VennMap is a small javascript library that allows the construction of a collection objects that can then be accessed by any member property of the objects added.
Indexes are generated on the first request to get a list of objects by key or keys. Those indexes are then maintained for the lifetime of the VennMap object.
The member properties on any object added are replaced by a getter/setter, allowing VennMap to move objects from one branch of an index to another.
VennMap will not perform as well where the number of get requests is low compared to the number of inserts, or on very small sets of data compared with simply enumerating all objects your self. It does however provide a very convenient way of storing and retrieving objects.
var VennMap=require("vennmap");
var vm=new VennMap();
//
vm.add({"group":"Vehicles","type":"Car","maker":"Volvo", "details": {"year":1999}});
vm.add({"group":"Vehicles","type":"Car","maker":"Ford", "details": {"year":1997}});
vm.add({"group":"Vehicles", "type":"Van","maker":"Vauxhall","details": {"year":1999}});
vm.get({"details":{"year":1999}}) // returns the Volvo and Vauxhall above
vm.get({"group":"Vehicles"}) // returns all 3 items above
var newCar={"group":"Vehicles","type":"Car","maker":"Bentley", "details": {"year":2010}};
vm.add(newCar);
//to remove it
vm.remove(newCar);
Note that VennMap adds a function closure to your object in order to track it. This function closure will not been seen when you serialize to JSON.