zoukankan      html  css  js  c++  java
  • javascript中实现的hashtable

    function Hashtable()
    {
        
    this._hash      = new Object();
        
    this.add        = function(key,value){
                            
    if(typeof(key)!="undefined"){
                                
    if(this.contains(key)==false){
                                    
    this._hash[key]=typeof(value)=="undefined"?null:value;
                                    
    return true;
                                }
     else {
                                    
    return false;
                                }

                            }
     else {
                                
    return false;
                            }

                        }

        
    this.remove        = function(key){delete this._hash[key];}
        
    this.count        = function(){var i=0;for(var k in this._hash){i++;} return i;}
        
    this.items        = function(key){return this._hash[key];}
        
    this.contains    = function(key)return typeof(this._hash[key])!="undefined";}
        
    this.clear        = function(){for(var k in this._hash){delete this._hash[k];}}

    }


    var a = new Hashtable();

    a.add(
    "aa");
    a.add(
    "bb",2342);
    a.add(
    "bb",2342);

    a.remove(
    "aa");

    alert(a.count());

    alert(a.contains(
    "bb"));

    alert(a.contains(
    "aa"));

    alert(a.items(
    "bb"));
  • 相关阅读:
    HNU 12906 Battleship
    codeforces 261 D
    HDU 4939 Stupid Tower Defense(dp)
    HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
    HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
    【转载】使用Pandas对数据进行筛选和排序
    【转载】使用pandas进行数据清洗
    【转载】VC维的来龙去脉
    Python-时间操作
    Pandas-数据导入
  • 原文地址:https://www.cnblogs.com/jacktu/p/1011504.html
Copyright © 2011-2022 走看看