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];
		}
	}

}

相关文章:

  • 2022-12-23
  • 2021-09-14
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2021-06-01
  • 2022-01-19
猜你喜欢
  • 2021-05-16
  • 2021-08-16
  • 2021-12-02
  • 2022-12-23
  • 2021-06-12
  • 2021-10-25
  • 2021-08-05
相关资源
相似解决方案