Implementación de JavaScript de diccionario
Ideas de programación:
Código:
function () {"use estricto"; función diccionary () {this._size = 0; this.datastore = object.create (nulo); } Diccionario.prototype.isempty = function () {return this._size === 0; }; Diccionario.prototype.size = function () {return this._size; }; Dictionary.prototype.clear = function () {for (var key en this.datastore) {eliminar this.datastore [key]; } this._size = 0; }; Dictionary.prototype.add = function (key, value) {this.datastore [key] = valor; this._size ++; }; Diccionario.prototype.find = function (key) {return this.datastore [clave]; }; Diccionario.prototype.count = function () {var n = 0; para (var key en this.datastore) {n ++; } return n; }; Dictionary.prototype.remove = function (key) {eliminar this.datastore [key]; this._size--; }; Dictionary.prototype.showall = function () {for (var key en this.datastore) {console.log (key + "->" + this.datastore [key]); }}; módulo.exports = diccionario;}) ();Implementación de JavaScript de hash (hashtable)
Ideas de programación:
Código:
valuepair.js
(function () {"use Strict"; function valuePair (key, value) {this.key = key; this.Value = value;} valuePair.prototype.ToString = function () {return "[" + they + ":" + this.value + "]";}; módulo.exports = valeuePair;}) (););Hashtable.js
(function () {"use Strict"; var valuePair = request ("./ lib/valuePair"); var linkedList = require ("./ linkedList"); function hashtable () {this.table = object.create (null); this._size = 0;} Hashtable.pototype.isempty Hashtable.prototype.size = function () {return this._size; Currnode.next; } else {var currnode = this.table [index] .gethead (); if (this.table [index] == null) {this.table [index] = new LinkedList (); Valor; for (var en este.table) {var currnode = this.table [key] .gethead (); *****************************/function hashcode (key) {// algoritmo de Horner, el número primario es 37 var HashValue = 6011; Hashtable;}) ();