Javascript Hashtable 类

  1. /*******************************************************************
  2. *Yabin  Write by 2007.9.19
  3. * Hashtable 集合类
  4. *
  5. ********************************************************************/
  6. function HBHashtable()
  7. {
  8.     this._hashValue = new Object();
  9.     this._iCount=0;
  10. }
  11. HBHashtable.prototype.put =function(strKey,value)
  12. {
  13.     if (typeof(strKey)=="string")
  14.     {
  15.         this._hashValue[strKey]=typeof(value)!="undefined"?value:null;
  16.         this._iCount++;
  17.         return true;
  18.     }   
  19.     else
  20.         throw "哈希键值不能为空!";
  21. }
  22. HBHashtable.prototype.get =function(key)
  23. {
  24.     if (typeof(key)=="string")
  25.         return this._hashValue[key];
  26.     if (typeof(key)=="number")
  27.         return this._getCellByIndex(key);
  28.     else
  29.         throw "哈希键值不能为空!";
  30. }
  31. HBHashtable.prototype.findKey =function(iIndex)
  32. {
  33.     if (typeof(iIndex)=="number")
  34.         return this._getCellByIndex(iIndex,false);
  35.     else
  36.         "";
  37. }
  38. HBHashtable.prototype.count =function()
  39. {
  40.     return this._iCount; 
  41. }
  42. HBHashtable.prototype._getCellByIndex =function(iIndex,bIsGetValue)
  43. {
  44.     var i=0;
  45.     if(bIsGetValue==null)bIsGetValue=true;
  46.     for (var key in this._hashValue)
  47.     {
  48.         if (i==iIndex)
  49.         {
  50.             return bIsGetValue?this._hashValue[key]:key;
  51.         }
  52.         i++;
  53.     }
  54. }
  55. HBHashtable.prototype.remove=function(key)
  56. {
  57.     for (var strKey in this._hashValue)
  58.     {
  59.         if (key==strKey)
  60.         {
  61.             delete this._hashValue[key];
  62.             this._iCount--;
  63.         }   
  64.     }
  65. }
  66. HBHashtable.prototype.clear=function()
  67. {
  68.     for (var key in this._hashValue)
  69.     {
  70.         delete this._hashValue[key];
  71.     }
  72.     this._iCount=0;
  73. }
  74. HBHashtable.prototype.toString=function()
  75. {
  76.     return HBDataConvert.ToString(this);
  77. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值