Implementasi kamus javascript
Ide Pemrograman:
Kode:
function () {"gunakan ketat"; fungsi kamus () {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 (tombol var di this.datastore) {hapus this.datastore [key]; } this._size = 0; }; Dictionary.prototype.add = function (key, value) {this.datastore [key] = value; this._size ++; }; Dictionary.prototype.find = function (key) {return this.datastore [key]; }; Dictionary.prototype.count = function () {var n = 0; untuk (tombol var di this.datastore) {n ++; } return n; }; Dictionary.prototype.remove = function (key) {hapus this.datastore [key]; this._size--; }; Dictionary.prototype.showall = function () {for (var Key di this.datastore) {console.log (key + "->" + this.datastore [key]); }}; module.Exports = kamus;}) ();Implementasi Hash JavaScript (Hashtable)
Ide Pemrograman:
Kode:
valuepair.js
(function () {"Gunakan strict"; function valuePair (key, value) {this.key = key; this.value = value;} valuePair.pototype.toString = function () {return "[" + this.key + ":" + this.value + "];hashtable.js
(function () {"Gunakan ketat"; var valuePair = membutuhkan ("./ lib/valuePair"); var linkedlist = membutuhkan ("./ LinkedList"); function hashtable () {this.table = objek.create (null); this._size = 0;} hashtable.prototype = null); this._size = 0;} hashtable.protype. Hashtable.prototype.size = function () {return this._size; Currnode.Next; } {var Currnode = this.table [index] .gethead (); if ini.table [index] == null) {this.table [index] = new LinkedList (); nilai; Kunci dalam hal ini *************************** HashCode (Key) {// Algoritma Horner, bilangan prima adalah 37 var hashvalue = 6011; Hashtable;}) ();