zoukankan      html  css  js  c++  java
  • *JS实现HashTable的例子

     1<script language="javascript" type="text/javascript">
     2
     3function Hashtable()
     4{
     5    this._hash        = new Object();
     6    this.add        = function(key,value){
     7                        if(typeof(key)!="undefined"){
     8                            if(this.contains(key)==false){
     9                                this._hash[key]=typeof(value)=="undefined"?null:value;
    10                                return true;
    11                            }
     else {
    12                                return false;
    13                            }

    14                        }
     else {
    15                            return false;
    16                        }

    17                    }

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

    25
    26var a = new Hashtable();
    27
    28a.add("aa");
    29a.add("bb",2342);
    30a.add("bb",2342);
    31
    32a.remove("aa");
    33
    34alert(a.count());
    35
    36alert(a.contains("bb"));
    37
    38alert(a.contains("aa"));
    39
    40alert(a.items("bb"));
    41
    42
    43</script>
  • 相关阅读:
    lcn 分布式事务协调者集群原理
    springboot 监控 Actuator
    springboot 配置文件说明
    docker 安装jenkins
    docker 搭建maven 私服
    docker 安装 gitlab
    docker 安装软件
    docker 部署 java 项目
    mybatis 中between and用法
    vue-router history 模式 iis 配置
  • 原文地址:https://www.cnblogs.com/dwjaissk/p/667986.html
Copyright © 2011-2022 走看看