UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

2 lines (1 loc) 859 B
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t=require("./LinkedList.js"),e=function(e){this._list=new t.default,this._map={},this._maxSize=e||10};e.prototype.setMaxSize=function(t){this._maxSize=t},e.prototype.put=function(t,e){if(!this._map.hasOwnProperty(t)){var i=this._list.length();if(i>=this._maxSize&&i>0){var s=this._list.head;this._list.remove(s),delete this._map[s.key]}var r=this._list.insert(e);r.key=t,this._map[t]=r}},e.prototype.get=function(t){var e=this._map[t];if(this._map.hasOwnProperty(t))return e!==this._list.tail&&(this._list.remove(e),this._list.insertEntry(e)),e.value},e.prototype.remove=function(t){var e=this._map[t];void 0!==e&&(delete this._map[t],this._list.remove(e))},e.prototype.clear=function(){this._list.clear(),this._map={}};var i=e;exports.default=i;