Implémentation JavaScript du dictionnaire
Idées de programmation:
Code:
function () {"Utiliser Strict"; fonction 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 = fonction (key, valeur) {this.datastore [key] = value; this._size ++; }; Dictionary.prototype.find = function (key) {return this.datastore [key]; }; Dictionary.prototype.count = function () {var n = 0; pour (clé var dans ce.datastore) {n ++; } return n; }; Dictionary.prototype.remove = function (key) {supprimer this.datastore [key]; this._size--; }; Dictionary.prototype.showall = function () {for (var key in this.datastore) {console.log (key + "->" + this.datastore [key]); }}; module.exports = dictionary;}) ();Implémentation JavaScript de Hash (HashTable)
Idées de programmation:
Code:
valluepair.js
(function () {"Utiliser strict"; fonction Valuepair (key, value) {this.key = key; this.value = value;} valuepair.prototype.tostring = function () {return "[" + this.key + ":" + this.value + "]";}; module.exports = valiepair;}) (););););hashtable.js
(function () {"Utiliser strict"; var valisepair = require ("./ lib / vallepair"); var liendList = require ("./ linkedList"); fonction hashTable () {this.Table = object.create (null); this._size = 0;} hashtable.prototype.isempty = function () {renvoie this._size == 0; 0; HashTable.prototype.size = fonction () {return this._size;}; Currnode.next; } else {var currnode = this.table [index] .gethead (); if (this.Table [index] == null) {this.Table [index] = new LinkedList ();} var currnode = this.Table [if]. Valeur; Key dans ce.Table) {var currnode = this.Table [Key] .GetHead (); ************************* / FONCTION HASHCODE (KEY) {// L'algorithme de Horner, le numéro de premier ordre est 37 var hashvalue = 6011; Hashtable;}) ();