Implementação de JavaScript do Dicionário
Idéias de programação:
Código:
function () {"use Strict"; function dictionary () {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 tecla em this.datastore) {exclui this.datastore [key]; } this._size = 0; }; Dictionary.prototype.add = function (chave, valor) {this.datastore [key] = value; this._size ++; }; Dictionary.prototype.find = function (key) {return this.datastore [key]; }; Dictionary.prototype.count = function () {var n = 0; for (var tecla var neste.dataStore) {n ++; } retornar n; }; Dictionary.prototype.remove = function (key) {excluir this.datastore [key]; this._size--; }; Dictionary.prototype.showall = function () {for (var tecla this.datastore) {console.log (key + "->" + this.datastore [key]); }}; module.exports = dictionary;}) ();Implementação de JavaScript de Hash (hashtable)
Idéias de programação:
Código:
valuepair.js
(function () {"use rigoroso"; function valuepair (key, value) {this.key = key; this.value = value;} valuepair.prototype.toString = function () {return "[" + this.key + ":" + this.value + "]";}; module.exports = valuepir;hashtable.js
(function () {"use strict"; var valuepair = requer ("./ libex/valuepair"); var linkedList = requer ("./ linkedList"); function hashtable () {thishtable.Protype.Create (null); this._size = 0;} hashtotypy.ProtyPy.ismemt (null); Hashtable.protype.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; Chave neste.Table) {varrnode = this.table [key] .gethead (); ***************************/função HashCode (Key) {// Algoritmo de Horner, o número do primo é 37 var hashvalue = 6011; Hashtable;}) ();