- /*******************************************************************
- *Yabin Write by 2007.9.19
- * Hashtable 集合类
- *
- ********************************************************************/
- function HBHashtable()
- {
- this._hashValue = new Object();
- this._iCount=0;
- }
- HBHashtable.prototype.put =function(strKey,value)
- {
- if (typeof(strKey)=="string")
- {
- this._hashValue[strKey]=typeof(value)!="undefined"?value:null;
- this._iCount++;
- return true;
- }
- else
- throw "哈希键值不能为空!";
- }
- HBHashtable.prototype.get =function(key)
- {
- if (typeof(key)=="string")
- return this._hashValue[key];
- if (typeof(key)=="number")
- return this._getCellByIndex(key);
- else
- throw "哈希键值不能为空!";
- }
- HBHashtable.prototype.findKey =function(iIndex)
- {
- if (typeof(iIndex)=="number")
- return this._getCellByIndex(iIndex,false);
- else
- "";
- }
- HBHashtable.prototype.count =function()
- {
- return this._iCount;
- }
- HBHashtable.prototype._getCellByIndex =function(iIndex,bIsGetValue)
- {
- var i=0;
- if(bIsGetValue==null)bIsGetValue=true;
- for (var key in this._hashValue)
- {
- if (i==iIndex)
- {
- return bIsGetValue?this._hashValue[key]:key;
- }
- i++;
- }
- }
- HBHashtable.prototype.remove=function(key)
- {
- for (var strKey in this._hashValue)
- {
- if (key==strKey)
- {
- delete this._hashValue[key];
- this._iCount--;
- }
- }
- }
- HBHashtable.prototype.clear=function()
- {
- for (var key in this._hashValue)
- {
- delete this._hashValue[key];
- }
- this._iCount=0;
- }
- HBHashtable.prototype.toString=function()
- {
- return HBDataConvert.ToString(this);
- }
Javascript Hashtable 类
最新推荐文章于 2024-07-05 16:41:23 发布