zoukankan      html  css  js  c++  java
  • Simple javascript HashMap

    function each(object, callback) {
    	if (undefined === object.length) {
    		for ( var name in object) {
    			if (false === callback(object[name], name, object))
    				break;
    		}
    	} else {
    		for ( var i = 0, len = object.length; i < len; i++) {
    			if (i in object) {
    				if (false === callback(object[i], i, object))
    					break;
    			}
    		}
    	}
    }
    
    var Map = function() {
    	this.keySet = new Array();
    	this.values = new Array();
    }
    
    Map.prototype.put = function(mKey, mValues) {
    	this.keySet.push(mKey);
    	this.values.push(mValues);
    }
    
    Map.prototype.updateKeyValue = function(mKey, mValues) {
    	if (this.keySet == null) {
    		return null;
    	}
    
    	var hasKey = false, mIndex = -1;
    
    	each(this.keySet, function(o, index) {
    		if (mKey == o) {
    			mIndex = index;
    			hasKey = true;
    			return false;
    		}
    	})
    
    	if (hasKey == false) {
    		this.keySet.push(mKey);
    		this.values.push(mValues);
    	} else {
    		if (mIndex != -1) {
    			this.values[mIndex] = mValues;
    		}
    	}
    }
    
    Map.prototype.get = function(mKey) {
    
    	if (this.keySet == null) {
    		return null;
    	}
    
    	for ( var i = 0; i < this.keySet.length; i++) {
    		if (mKey == this.keySet[i]) {
    			return this.values[i];
    		}
    	}
    
    }
    

  • 相关阅读:
    安装apache服务
    基于mysqld_multi实现MySQL 5.7.24多实例多进程配置
    linux安装lolcat实现彩色文字输出信息
    haproxy+keepalived实现高可用
    LVS DR模拟实验
    nginx+keepalived实现高可用
    cpu相关信息查看
    LVS集群
    session之memcache
    tomcat之redis
  • 原文地址:https://www.cnblogs.com/wblade/p/1684627.html
Copyright © 2011-2022 走看看