/* * å®ä¹åå ¸ç±» */ module.exports = function Dict() { this.datastore = {}; this.set = set; this.has = has; this.get = get; this.remove = remove; this.keys = keys; this.values = values; this.showAll = showAll; this.size = size; this.clear = clear; } // æ·»å æ°æ® function set(key, value) { this.datastore[key] = value; } // 夿æ¯å¦æè¯¥æ°æ® function has(key) { return this.datastore.hasOwnProperty(key); } // æ ¹æ®keyå»è·åvalue function get(key) { return this.has(key) ? this.datastore[key] : undefined; } // è·åææçkey function keys() { return Object.keys(this.datastore); } // è·åææçvalue function values() { return Object.values(this.datastore); } // å 餿°æ® function remove(key) { delete this.datastore[key]; } // æ¾ç¤ºæææ°æ® // å¹¶å¯¹ç»æè¿è¡äºæåº function showAll() { for(var key in Object.keys(this.datastore).sort()) { print(key + " -> " + this.datastore[key]); } } // è¿åå ç´ ä¸ªæ° function size() { return this.keys().length; } // æ¸ ç©ºåå ¸ function clear() { this.datastore = {}; }