夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          function Hashtable() 
                  
          {
                      
          this.container = new Object();
                      
                      
          /** put element */
                      
          this.put = function (key, value) 
                      
          {
                          
          if (typeof (key) == "undefined")
                          
          {
                              
          return false;
                          }
           
                          
          if (this.contains(key))
                          
          {
                              
          return false;
                          }
           
                          
          this.container[key] = typeof (value) == "undefined" ? null : value;
                          
          return true;
                      }
          ;
                  
                      
          /** remove element */
                      
          this.remove = function (key) 
                      
          {
                          
          delete this.container[key];
                      }
          ;
                      
                      
          /** get size */
                      
          this.size = function () 
                      
          {
                          
          var size = 0;
                          
          for (var attr in this.container) 
                          
          {
                              size
          ++;
                          }

                          
          return size;
                      }
          ;
                      
                      
          /** get value by key */
                      
          this.get = function (key) 
                      
          {
                          
          return this.container[key];
                      }
          ;
                  
                      
          /** containts a key */
                      
          this.contains = function (key) 
                      
          {
                          
          return typeof (this.container[key]) != "undefined";
                      }
          ;
                  
                      
          /** clear all entrys */
                      
          this.clear = function () 
                      
          {
                          
          for (var attr in this.container)
                          
          {
                              
          delete this.container[attr];
                          }

                      }
          ;
                      
                      
          /** hashTable 2 string */
                      
          this.toString = function()
                      
          {
                          
          var str = "";
                          
          for (var attr in this.container)
                          
          {
                              str 
          += "," + attr + "=" + this.container[attr];
                          }

                          
          if(str.length>0)
                          
          {
                              str 
          = str.substr(1, str.length);
                          }

                          
          return "{" + str + "}";
                      }
          ;
                  }

                  
                  
          var hashtable = new Hashtable();
                  hashtable.put('
          1','huyvanpull');
                  hashtable.put('
          2','ensoodge');
                  hashtable.put('
          3','huyfan');
                  
                  hashtable.remove('
          2');
                  alert(hashtable.toString());
          posted on 2009-10-16 15:09 HUIKK 閱讀(1897) 評論(1)  編輯  收藏 所屬分類: JavaScript

          評論

          # re: js hashTable 2009-10-16 17:44 翔南
          不錯 收藏!  回復  更多評論
            

          主站蜘蛛池模板: 内丘县| 汝阳县| 牙克石市| 博白县| 嫩江县| 洪雅县| 聂荣县| 枣强县| 鄂尔多斯市| 浮山县| 鹰潭市| 资源县| 保定市| 四平市| 永顺县| 新源县| 广平县| 九江市| 梨树县| 南投县| 天全县| 察雅县| 荣昌县| 谷城县| 秦皇岛市| 大关县| 旬阳县| 洪江市| 哈尔滨市| 杭锦后旗| 沙田区| 连云港市| 柳河县| 青岛市| 广宗县| 瑞安市| 荣成市| 镇平县| 措勤县| 邢台市| 青龙|