zoukankan      html  css  js  c++  java
  • jquery哈希表

    jQuery.Hashtable = function () {
        
    this.items = new Array();
        
    this.itemsCount = 0;
        
    this.add = function (key, value) {
            
    if (!this.containsKey(key)) {
                
    this.items[key] = value;
                
    this.itemsCount++;
            }
            
    else {
                
    //throw "key '" + key + "' allready exists."
                this.items[key] = value;
            }
        }

        
    this.get = function (key) {
            
    if (this.containsKey(key))
                
    return this.items[key];
            
    else
                
    return null;
        }

        
    this.remove = function (key) {
            
    if (this.containsKey(key)) {
                delete 
    this.items[key];
                
    this.itemsCount--;
            }
            
    else
                
    throw "key '" + key + "' does not exists."

        }

        
    this.containsKey = function (key) {
            
    return typeof (this.items[key]) != "undefined";
        }

        
    this.containsValue = function containsValue(value) {
            
    for (var item in this.items) {
                
    if (this.items[item] == value)
                    
    return true;
            }

            
    return false;
        }

        
    this.contains = function (keyOrValue) {
            
    return this.containsKey(keyOrValue) || this.containsValue(keyOrValue);
        }

        
    this.clear = function () {
            
    this.items = new Array();
            itemsCount 
    = 0;
        }

        
    this.size = function () {
            
    return this.itemsCount;
        }

        
    this.isEmpty = function () {
            
    return this.size() == 0;
        }
    };

    使用方法:

    var hashtable = new jQuery.Hashtable(); 
            hashtable.add(
    "hello",["world","hello world"]);
            hashtable.add(
    "aaa",["111","3333"]);
            alert(hashtable.get(
    "aaa")[1]);


     

  • 相关阅读:
    spark-submit配置说明
    spark dataset join 使用方法java
    关于join算法的四篇文章
    IO负载高的来源定位
    MySQL执行SHOW STATUS查询服务器状态状态之Handler_read_* 详解
    5.6中使用字符串存放时间,导致隐式转换发生的记录
    Linux User's Manual IOSTAT
    【转】MegaSAS RAID卡 BBU Learn Cycle周期的影响
    mac下SSH很快被断开
    Java的正则表达式
  • 原文地址:https://www.cnblogs.com/timy/p/1986039.html
Copyright © 2011-2022 走看看