Sha256: 8c043229d2d9dbe225cd9fda347fb925c6a7a47d1caaaf381f2a65943cc00bea

Contents?: true

Size: 1.62 KB

Versions: 71

Compression:

Stored size: 1.62 KB

Contents

/**
	@constructor
	@example
	var _index = new Hash();
	_index.set("a", "apple");
	_index.set("b", "blue");
	_index.set("c", "coffee");

	for (var p = _index.first(); p; p = _index.next()) {
		print(p.key+" is for "+p.value);
	}
	
 */
var Hash = function() {
	this._map = {};
	this._keys = [];
	this._vals = [];
	this.reset();
}

Hash.prototype.set = function(k, v) {
	if (k != "") {
		this._keys.push(k);
		this._map["="+k] = this._vals.length;
		this._vals.push(v);
	}
}

Hash.prototype.replace = function(k, k2, v) {
	if (k == k2) return;

	var offset = this._map["="+k];
	this._keys[offset] = k2;
	if (typeof v != "undefined") this._vals[offset] = v;
	this._map["="+k2] = offset;
	delete(this._map["="+k]);
}

Hash.prototype.drop = function(k) {
	if (k != "") {
		var offset = this._map["="+k];
		this._keys.splice(offset, 1);
		this._vals.splice(offset, 1);
		delete(this._map["="+k]);
		for (var p in this._map) {
			if (this._map[p] >= offset) this._map[p]--;
		}
		if (this._cursor >= offset && this._cursor > 0) this._cursor--;
	}
}

Hash.prototype.get = function(k) {
	if (k != "") {
		return this._vals[this._map["="+k]];
	}
}

Hash.prototype.keys = function() {
	return this._keys;
}

Hash.prototype.hasKey = function(k) {
	if (k != "") {
		return (typeof this._map["="+k] != "undefined");
	}
}

Hash.prototype.values = function() {
	return this._vals;
}

Hash.prototype.reset = function() {
	this._cursor = 0;
}

Hash.prototype.first = function() {
	this.reset();
	return this.next();
}

Hash.prototype.next = function() {
	if (this._cursor++ < this._keys.length)
		return {key: this._keys[this._cursor-1], value: this._vals[this._cursor-1]};
}

Version data entries

71 entries across 70 versions & 12 rubygems

Version Path
hquery-patient-api-1.1.1 doc/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-1.1.0 doc/jsdoc-toolkit/app/frame/Hash.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/JSV/jsdoc-toolkit/app/frame/Hash.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/JSV/jsdoc-toolkit/app/frame/Hash.js
quentonc-jsdoc_helper-0.0.2 ext/jsdoc-toolkit/app/frame/Hash.js
quentonc-jsdoc_helper-0.0.2 test/ext/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-1.0.4 doc/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-1.0.3 doc/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-1.0.2 doc/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-1.0.1 doc/jsdoc-toolkit/app/frame/Hash.js
jsc3d-rails-1.0 vendor/assets/javascripts/tools/doc_generator/app/frame/Hash.js
hquery-patient-api-1.0.0 doc/jsdoc-toolkit/app/frame/Hash.js
hquery-patient-api-0.3.0 doc/jsdoc-toolkit/app/frame/Hash.js
distil-0.14.5.a vendor/jsdoc-toolkit/app/frame/Hash.js
jsdoc-rails-0.1 jsdoc-toolkit/app/frame/Hash.js
distil-0.14.4 vendor/jsdoc-toolkit/app/frame/Hash.js
sc-docs-0.0.3 vendor/jsdoc/app/frame/Hash.js
sc-docs-0.0.2 vendor/jsdoc/app/frame/Hash.js
sc-docs-0.0.1 vendor/jsdoc/app/frame/Hash.js
distil-0.14.3 vendor/jsdoc-toolkit/app/frame/Hash.js