辞書のJavaScript実装
プログラミングのアイデア:
コード:
function(){"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(this.datastore){delete 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; for(this.datastoreのvarキー){n ++; } return n; }; dictionary.prototype.remove = function(key){this.datastore [key]; this._size--; }; dictionary.prototype.showall = function(){for(this.datastore){console.log(key + " - >" + this.datastore [key]); }}; module.exports = dictionary;})();ハッシュのJavaScriptの実装(ハッシュテーブル)
プログラミングのアイデア:
コード:
ValuePair.js
(function(){"Strict"を使用します; function ValuePair(key、value){this.key = key; this.value = value.valepair.prototype.tostring = function(){return "[" + this.key + ":" + this.value + "]";}; module.exports = valuepair;});hashtable.js
(function(){ "use strict"; var ValuePair = require("./lib/ValuePair"); var LinkedList = require("./LinkedList"); function Hashtable(){ this.table = Object.create(null); this._size = 0; } Hashtable.prototype.isEmpty = function(){ return this._size === 0; }; prototype.size = function(){hashtable.remove = function {key = hashcode(key); currnode.key == currnode [currnode.element); } var currnode = table [index]; if.table [index] == null){this.table] = new linkedlist();値(null && currnode.value! This.table){var currnode [key] .gethead(); *********************/Function HashCode(// Hornerのアルゴリズム、var i = 0; i <key.length; i ++){hashvalue = hashvalue*37+key.charcodeat(i); hashtable;})();