• js 定义hash类


    // 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)
    看板管理(1)
    交互原型图
    Sequence Diagram时序图
    安卓项目的「轻」架构
    安卓ButtomBar实现方法
    工具类BitMap 把网络URL图片转换成BitMap
    使用OkHttp上传图片到服务器
    BaseAdapter教程(2) BaseAdapter的notifyDataSetChanged动态刷新
    开发中时间变换问题汇总
  • 原文地址:https://www.cnblogs.com/hqu-ye/p/3322155.html
Copyright © 2020-2023  润新知