🎜> |
|
1 |
樓盤開業 折扣大大 |
2011-11-11 |
簡訊通知 |
2 |
樓盤開業 折扣大大 |
2011-11- 11 |
簡訊通知 |
div>
}); }); }); >});
function HashMap()
{
/**Map size **/
var size = 0;
/**Object **/
var entry = new Object();
/**live **/
this.put = function (key , value)
{
if(!this.containsKey(key))
{
size ;
}
entry[key] = value;
}
/**Pick **/
this.get = function (key)
{
if( this.containsKey(key) )
{
return entry[key];
}
else
{
return null;
}
}
/**delete **/
this.remove = function ( key )
{
if( delete entry[key] )
{
size --;
}
}
/**Whether to include Key **/
this.containsKey = function ( key )
{
return (key in entry);
}
/**Whether to include Value **/
this.containsValue = function ( value )
{
for(var prop in entry)
{
if(entry[prop] == value)
{
return true;
}
}
return false;
}
/**All Value **/
this.values = function ()
{
var values = new Array(size);
for(var prop in entry)
{
values.push(entry[prop]);
}
return values;
}
/**All Key **/
this.keys = function ()
{
var keys = new Array(size);
for(var prop in entry)
{
keys.push(prop);
}
return keys;
}
/**Map Size **/
this.size = function ()
{
return size;
}
}
// var map = new HashMap();
/*
map.put("A","1");
map.put("B","2");
map.put("A","5");
map.put("C","3");
map.put("A","4");
*/
/*
alert(map.containsKey("XX"));
alert(map.size());
alert(map.get("A"));
alert(map.get("XX"));
map.remove("A");
alert(map.size());
alert(map.get("A"));
*/
/**You can also use the object as Key **/
/*
var arrayKey = new Array("1","2","3","4");
var arrayValue = new Array("A","B","C","D");
map.put(arrayKey,arrayValue);
var value = map.get(arrayKey);
for(var i = 0 ; i < value.length ; i )
{
//alert(value[i]);
}
*/
/**When an object is used as a Key, the toString() method of the object is automatically called. In fact, the String object is ultimately used as the Key**/
/**If it is a custom object, you have to override the toString() method. Otherwise, . will be the following result **/
// function MyObject(name)
// {
// this.name = name;
// }
/**
function MyObject(name)
{
this.name = name;
this.toString = function ()
{
return this.name;
}
}
**/
// var object1 = new MyObject("小张");
// var object2 = new MyObject("小名");
//
// map.put(object1,"小张");
// map.put(object2,"小名");
// alert(map.get(object1));
// alert(map.get(object2));
// alert(map.size());
//
/**Running result Nickname Nickname size = 1 **/
/**If you change it to an object that overrides the toString() method, the effect will be completely different **/