`
xiegangthrille
  • 浏览: 92119 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

用javascript封装的一个HashMap,形似神非

阅读更多
function HashMap(){
            this.size=0;
            this.map=new Object();
        }
        
        HashMap.prototype.put=function(key,value){
            if(!this.map[key]){
                this.size++;
            }
            this.map[key]=value;
        }
        HashMap.prototype.get=function(key){
            return this.isKey(key)?this.map[key]:null;
        }
        HashMap.prototype.isKey=function(key){
            return (key in this.map);
        }
        HashMap.prototype.remove=function(key){
          if( this.isKey(key) && (delete this.map[key])){  
                this.size--;  
          }  
        }
        
        HashMap.prototype.size=function(){
            return this.size;
        }
        
        HashMap.prototype.find=function(_callback){
            for(var _key in this.map){
                _callback.call(this,_key,this.map[_key]);
            }
        }
function testHashMap(){
            var map=new HashMap();
            map.put("a","中");
            map.put("b","国");
            map.put("c","人");
            map.put("d","民");
            
            //map.remove("a");
            map.remove("b");
            map.find(function(key,value){
                map.remove(key);
            });
            alert(map.size());
        }

 

分享到:
评论

相关推荐

    Javascript实现和操作HashMap

    Javascript实现和操作HashMap,压缩包里面有hashmap定义和操作的例子

    一个基于js的HashMap

    一个用于js里面 用javascript实现的HashMap类

    HashMap的二次封装

    理解面向对象后的代码抽取,HashMap的二次封装,总之目的减少点代码工作量,见代码示例

    javaScript模拟的HashMap数据结构的对象

    javaScript模拟的HashMap数据结构,可以方便的put和get。几乎和Java中HashMap类的功能一模一样。非常好用的!

    基于JavaScript的HashMap实现

    NULL 博文链接:https://mox-sir.iteye.com/blog/2124644

    用HashMap模拟一个网上购物车

    1. 用HashMap模拟一个网上购物车。要求:从键盘输入5本书的名称、单价、购买数量,将这些信息存入一个HashMap,然后将该HashMap作为参数调用方法getSum(HashMap books),该方法用于计算书的总价并返回。【说明:...

    flex HashMap

    flex 封装的一个HashMap。使用挺方便的。(免积分下载)

    HashMap介绍和使用

    HashMap介绍和使用

    一个delphi的hashmap源代码

    一个delphi写的hashmap源代码, 包括TIntegerHashList, TStringHashList, TObjectHashList. 十万条记录查找只用 400毫秒.

    用HashMap写的一个小Demo用来写游戏排名的一种方法

    用HashMap写的一个小的一个游戏排名的小demo。

    C++hashmap的使用实例

    C++hashmap的使用实例

    HashMap的一个数据结构

    HashMap的一个数据结构 锁升级:锁升级过程 resize的过程在开发中 怎么保证容器它线程安全后就是数据插入过程使用的头插法 但是头插法会造成一些问题等等等等的那个等等的那个等等的那个等等的那个等等的那个等等的...

    hashmap 实例

    hashmap实例 hashmap实例hashmap实例hashmap实例

    HashMap排序

    hashMap排序,hashmap使用还是比较频繁。这时自己写的一个实现hashmap排序的例子

    hashmap面试题_hashmap_

    hashmap相关的面试题

    前端开源库-hashmap

    前端开源库-hashmaphashmap,用于javascript的hashmap类

    java中HashMap详解

    非线程安全:如果多个线程同时访问同一个HashMap实例,可能会导致数据不一致的问题。因此,在使用HashMap时需要进行同步处理或者使用线程安全的HashMap实现类。 动态扩容:当HashMap中的元素数量超过了容量(默认为...

    怎样遍历一个HashMap?

    可以通过2种方法遍历HashMap <br>Map map = new HashMap(); <br>for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { <br> Map.Entry entry = (Map.Entry) iter.next(); <br> Object ...

    HashMap部分源码分析

    HashMap数据结构,HashMap的构造方法,HashMap的put,HashMap的get

    HashMap原理.docx

    HashMap是一个散列桶(数组和链表),它存储的内容是键值对(key-value)映射HashMap采用了数组和链表的数据结构,能在查询和修改方便继承了数组的线性查找和链表的寻址修改HashMap是非synchronized,所以HashMap很快...

Global site tag (gtag.js) - Google Analytics