تنفيذ JavaScript للقاموس
أفكار البرمجة:
شفرة:
function () {"استخدم صارم" ؛ دالة القاموس () {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 ؛ ل (مفتاح var في this.datastore) {n ++ ؛ } return n ؛ } ؛ dictionary.prototype.remove = function (key) {delete this.datastore [key] ؛ this._size-- ؛ } ؛ dictionary.prototype.showall = function () {for (var key in this.datastore) {console.log (key + "->" + this.datastore [key]) ؛ }} ؛ module.exports = dictionary ؛}) () ؛تنفيذ JavaScript لـ Hash (hashtable)
أفكار البرمجة:
شفرة:
valuepair.js
(function () {"use strict" ؛ function valuepair (key ، value) {this.key = key ؛ this.value =} valuepair.prototype.toString = function () {return "[" + this.key + ":" + this.value + "]hashtable.js
(function () {"استخدام صارم" ؛ var valuepair = require ("./ lib/valuepair") ؛ var linkedList = require ("./ linkedlist") ؛ function hashtable () {this.table = object.create (null) ؛ this._size = 0 ؛ hashtable.protype currnode.next ؛ } {var currnode = this.table [index]. if (this.table [index] == null) {this.table [index] = new LinkedList () ؛ القيمة ؛ لـ (مفتاح VAR في هذا *******************: hashtable ؛}) () ؛