JavaScript -Implementierung des Wörterbuchs
Programmierideen:
Code:
function () {"Strict verwenden"; Funktion 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 key in this.datastore) {delete this.datastore [key]; } this._size = 0; }; Dictionary.Prototype.Add = Funktion (Schlüssel, Wert) {that.Datastore [Schlüssel] = Wert; this._size ++; }; Dictionary.Prototype.find = Funktion (Schlüssel) {return this.datastore [Schlüssel]; }; Dictionary.Prototype.count = function () {var n = 0; für (var key in diesem.datastore) {n ++; } return n; }; Dictionary.Prototype.remove = function (Schlüssel) {löschen this.datastore [Schlüssel]; this._size--; }; Dictionary.Prototype.showall = function () {for (var key in this.datastore) {console.log (Schlüssel + "->" + thataTastore [Schlüssel]); }}; module.exports = dictionary;}) ();JavaScript -Implementierung von Hash (Hashtable)
Programmierideen:
Code:
ValuePair.js
(function () {"Strict"; Funktion ValuePair (Schlüssel, Wert) {this.key = key; this.value = value;} ValuePair.Prototype.toString = function () {return "[" + this.key + ":" + this.Value + "]";};Hashtable.js
(function () {"Strict"; var valuepair = require ("./ lib/valuePair"); var linkedList = require ("./ LinkedList"); Funktion hashtable () {this.table = Object.create (null); this._size = Disize this.prototype.isemptye = isempty = function (). Hashtable.Prototype.size = Funktion () {return this._size; Currnode.Next; } else {var currnode = this.table [index] .Gethead (); if (this. Wert; in diesem. Table) {var currnode ********************** Hashtable;}) ();