사전의 JavaScript 구현
프로그래밍 아이디어 :
암호:
function () { "Strict 사용"; 함수 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) {this.datastore [key]; } this._size = 0; }; dictionary.prototype.add = 함수 (키, 값) {this.datastore [key] = value; this._size ++; }; dictionary.prototype.find = function (key) {return this.datastore [key]; }; dictionary.prototype.count = function () {var n = 0; for (var key in this.datastore) {n ++; } return n; }; dictionary.prototype.remove = function (key) {this.datastore [key]; this._size-; }; dictionary.prototype.showall = function () {for (var key in this.datastore) {console.log (key + "->" + this.datastore [key]); }}; module.exports = dictionary;}) ();해시 (hashtable)의 JavaScript 구현
프로그래밍 아이디어 :
암호:
valuepair.js
(function () { "Strict 사용"; 함수 valuePair (키, 값) {this.key = key; this.value = value;} valuepair.tostring = function () {return "[" + this.key + ":" + this.value + ";}; module.exports = valuepair;} ()hashtable.js
(function () { "strict 사용"; valuepair = require ( "./ lib/valuepair"); var linkedList = require ( "./ linkedList"); function hashtable () {this.table = object.create (null); this._size = 0; hashtable.spototypy = retoy () hashtable.size = hashtable.remove (key); Currnode.next. var this.table [index]. if (this.table [index] == null) {this vale}} (currnode.next == value! var Currnode = this.gethead (currnode.next) {currnode.leg *******************/기능 해시 코드 (Key) {// Horner의 알고리즘은 37 var hashvalue = 6011; 해시 가능;}) ();