// JavaScript Document
function HashTable(){
    this._hash={};
    this._count=0;
    
    
    /**
    *添加或者更新key
    */
    this.put=function(key,value){
        if(this._hash.hasOwnProperty(key)){
            this._hash[key]=value;
            return true;
        }else{
                this._hash[key]=value;
                this._count++;
                return true;
            }
    }
    
    
    /**
    *获取key指定的值
    */
    this.get=function(key){
        if(this.containsKey(key))
            return this._hash[key];
    }    
    
    
    /**
    *获取元素个数
    */    
    this.size=function(){
        return this._count;
    }
    
    
    /**
    *检查是否为空
    */
    this.isEmpty=function(){
        if(this._count<=0)
            return true;
        else return false;
    }
    
    
    /**
    *检查是否包含指定的key
    */
    this.containsKey=function(){
            return this._hash.hasOwnPropetry(key);
    }
    
    
    /**
    *检查是否包含指定的value
    */
    this.containsValue=function(){
        for(var strKey in this._hash)
            if(this._hash[strKey]==value)
                return true;                
        return false;
    }
    
    
    /**
    *删除一个key
    */
    this.remove=function(key){
            delete this._hash[key];
            this._count--;
    }
    
    
    /**
    *删除所有的key
    */
    this.clear=function(){
        this._hash={};
        this._count=0;
    }
    
    
    /**
    *从HashTable中获取Key的集合,以数组的形式返回
    */
    this.keySet=function(){
        var arrKeySet= new Array();
        var index=0;
        for(var strKey in this._hash){
            arrKeySet[index++]=strKey;
        }
        return (arrKeySet.length==0)?null:arrKeySet;
    }
    
    
    /**
    *从HashTable中获取Key的集合,以数组的形式返回
    */
    this.values=function(){
        var arrValues= new Array();
        var index=0;
        for(var strKey in this._hash){
            arrValues[index++]=this._hash[strKey];
        }
        return (arrValues.length==0)?null:arrValues;
    }
}

最新文章

  1. AOJ 0033 Ball【DFS】
  2. (C++) Include 文件
  3. egrep 及扩展正则表达式
  4. WebResource.axd 404 错误
  5. codecademy-command line-inputoutput
  6. Linq to Entities
  7. View模版的设计
  8. J2SE7规范_2013.2_类
  9. ZOJ 3913 Bob wants to pour water
  10. Quartz2D 之 简单介绍
  11. JavaScript中国象棋程序(4) - 极大极小搜索算法
  12. laravel实现支付宝支付功能
  13. FIFO深度计算
  14. [转帖]pfSense软路由系统的使用
  15. 将图片嵌入到markdown文档中
  16. RabbmitMQ-组成及简单使用
  17. webpack的使用一
  18. HDU 1561 The more, The Better (有依赖背包 || 树形DP)
  19. HTML5开发——轻量级JSON存储解决方案Lawnchair.js
  20. CocoaPods 创建私有仓库

热门文章

  1. 【Mac + Pycharm】之实用东西以及配置东西
  2. 详解path和classpath的区别
  3. 登录shell与非登录shell读取文件过程
  4. Java对文件夹中的文件按修改时间排序
  5. cocos2d-x 3.0rc1 使用iconv库 解决UTF8乱码问题
  6. 去除app中的标题栏
  7. data standardization
  8. 【python】-- 进程与线程
  9. The given &#39;driver&#39; ] is unknown, Doctrine currently supports only the follo wing drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo
  10. 寻找第K大 网易2016实习研发工程师编程题