Thursday, February 28, 2008

Javascript HashMap Implementation

Function to be used as
var hasmp1=Collection.HashMap();
var hasmp2=Collection.HashMap();
alert("MAP1 :"+hasmp1.get('1')+" MAP2:"+hasmp2.get('1'));
Only a few Method is implemented as of Now.
  1. boolean isEmpty() Returns true if this map contains no key-value mappings.
  2. Set keySet() Returns a set view of the keys contained in this map.
  3. Object put(Object key, Object value) Associates the specified value with the specified key in this map.
  4. void putAll(Map m) Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
  5. Object remove(Object key) Removes the mapping for this key from this map if present.
  6. int size() Returns the number of key-value mappings in this map.
  7. Collection values() Returns a collection view of the values contained in this map.
var Collection={
var hashMap = {
put : function(key,val) {this[key] = val;},
get : function(key) {return this[key];}
return hashMap;

No comments: