JavaScript реализация словаря
Идеи программирования:
Код:
function () {"strict"; Функциональный словарь () {this._size = 0; this.datastore = object.create (null); } Dictionary.prototype.isempty = function () {return this._size === 0; }; Dictionary.prototype.size = function () {return this._size; }; Dictionary.prototype.clear = function () {for (var key in this.datastore) {delete this.datastore [key]; } this._size = 0; }; Dictionary.prototype.add = function (ключ, значение) {this.datastore [key] = value; this._size ++; }; Dictionary.prototype.find = function (key) {return this.datastore [key]; }; Dictionary.prototype.count = function () {var n = 0; for (var key in this.datastore) {n ++; } return n; }; Dictionary.prototype.remove = function (key) {delete this.datastore [key]; this._size--; }; Dictionary.prototype.showall = function () {for (var win in this.datastore) {console.log (key + "->" + this.datastore [key]); }}; module.exports = dictionary;}) ();JavaScript реализация хэша (хэштата)
Идеи программирования:
Код:
ValuePair.js
(function () {"используйте строгий"; функция ValuePair (Key, значение) {this.key = key; this.value = value;} valuePair.prototype.tostring = function () {return "[" + this.key + ":" + this.value + "]";}; module.exports = valuepair;hashtable.js
(function () {"strict"; var valuePair = require ("./ lib/valuepair"); var linkedlist = require (". Hashtable.prototype.size = function () {return this._size; currnode = currnode.next; null; HashCode (Key); currnode.elemp.value = value; Hashtable.prototype.display = function () {for (var in this. /***************************************** key.charcodeat (i);} return hashvalue % 1019;