zoukankan      html  css  js  c++  java
  • js创建hashtable

    function Hashtable() 
            
    {
                
    this.container = new Object();
                
                
    /** put element */
                
    this.put = function (key, value) 
                
    {
                    
    if (typeof (key) == "undefined")
                    
    {
                        
    return false;
                    }
     
                    
    if (this.contains(key))
                    
    {
                        
    return false;
                    }
     
                    
    this.container[key] = typeof (value) == "undefined" ? null : value;
                    
    return true;
                }
    ;
            
                
    /** remove element */
                
    this.remove = function (key) 
                
    {
                    
    delete this.container[key];
                }
    ;
                
                
    /** get size */
                
    this.size = function () 
                
    {
                    
    var size = 0;
                    
    for (var attr in this.container) 
                    
    {
                        size
    ++;
                    }

                    
    return size;
                }
    ;
                
                
    /** get value by key */
                
    this.get = function (key) 
                
    {
                    
    return this.container[key];
                }
    ;
            
                
    /** containts a key */
                
    this.contains = function (key) 
                
    {
                    
    return typeof (this.container[key]) != "undefined";
                }
    ;
            
                
    /** clear all entrys */
                
    this.clear = function () 
                
    {
                    
    for (var attr in this.container)
                    
    {
                        
    delete this.container[attr];
                    }

                }
    ;
                
                
    /** hashTable 2 string */
                
    this.toString = function()
                
    {
                    
    var str = "";
                    
    for (var attr in this.container)
                    
    {
                        str 
    += "," + attr + "=" + this.container[attr];
                    }

                    
    if(str.length>0)
                    
    {
                        str 
    = str.substr(1, str.length);
                    }

                    
    return "{" + str + "}";
                }
    ;
            }

            
            
    var hashtable = new Hashtable();
            hashtable.put('
    1','huyvanpull');
            hashtable.put('
    2','ensoodge');
            hashtable.put('
    3','huyfan');
            
            hashtable.remove('
    2');
            alert(hashtable.toString());

  • 相关阅读:
    【HDOJ5538】House Building(计算几何)
    maven操作
    Guava 是个风火轮之函数式编程(3)——表处理
    guava 学习笔记 使用瓜娃(guava)的选择和预判断使代码变得简洁
    guava 学习笔记(二) 瓜娃(guava)的API快速熟悉使用
    Google Guava官方教程(中文版)
    Guava中Predicate的常见用法
    guava函数式编程
    idea常用快捷键
    guava
  • 原文地址:https://www.cnblogs.com/fqs123456/p/3081502.html
Copyright © 2011-2022 走看看