@blackglory/structures
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.1.15](https://github.com/BlackGlory/structures/compare/v0.1.14...v0.1.15) (2021-05-15) | ||
### Features | ||
* add LRU ([c1f8550](https://github.com/BlackGlory/structures/commit/c1f855022a4c4ac770fddc7d59aed1cfcf49d75f)) | ||
### [0.1.14](https://github.com/BlackGlory/structures/compare/v0.1.13...v0.1.14) (2021-03-16) | ||
@@ -7,0 +14,0 @@ |
@@ -28,31 +28,37 @@ (function (global, factory) { | ||
function __classPrivateFieldGet(receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
function __classPrivateFieldGet(receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
} | ||
var _map$1; | ||
function __classPrivateFieldSet(receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
} | ||
var _map$2; | ||
class Emitter { | ||
constructor() { | ||
_map$1.set(this, new Map()); | ||
_map$2.set(this, new Map()); | ||
} | ||
on(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map$1).has(event)) | ||
__classPrivateFieldGet(this, _map$1).set(event, new Set()); | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (!__classPrivateFieldGet(this, _map$2).has(event)) | ||
__classPrivateFieldGet(this, _map$2).set(event, new Set()); | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.add(handler); | ||
} | ||
off(event, handler) { | ||
if (__classPrivateFieldGet(this, _map$1).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (__classPrivateFieldGet(this, _map$2).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.delete(handler); | ||
if (set.size === 0) | ||
__classPrivateFieldGet(this, _map$1).delete(event); | ||
__classPrivateFieldGet(this, _map$2).delete(event); | ||
} | ||
} | ||
emit(event, value) { | ||
if (__classPrivateFieldGet(this, _map$1).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (__classPrivateFieldGet(this, _map$2).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.forEach(cb => cb(value)); | ||
@@ -62,34 +68,34 @@ } | ||
} | ||
_map$1 = new WeakMap(); | ||
_map$2 = new WeakMap(); | ||
var _map; | ||
var _map$1; | ||
class HashSet { | ||
constructor(hash) { | ||
this.hash = hash; | ||
_map.set(this, new Map()); | ||
_map$1.set(this, new Map()); | ||
} | ||
add(value) { | ||
__classPrivateFieldGet(this, _map).set(this.hash(value), value); | ||
__classPrivateFieldGet(this, _map$1).set(this.hash(value), value); | ||
return this; | ||
} | ||
delete(value) { | ||
return __classPrivateFieldGet(this, _map).delete(this.hash(value)); | ||
return __classPrivateFieldGet(this, _map$1).delete(this.hash(value)); | ||
} | ||
has(value) { | ||
return __classPrivateFieldGet(this, _map).has(this.hash(value)); | ||
return __classPrivateFieldGet(this, _map$1).has(this.hash(value)); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _map$1).clear(); | ||
} | ||
values() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _map$1).values(); | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _map$1).size; | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_map$1 = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
[Symbol.iterator]() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _map$1).values(); | ||
} | ||
@@ -100,9 +106,7 @@ } | ||
function createCommonjsModule(fn) { | ||
var module = { exports: {} }; | ||
return fn(module, module.exports), module.exports; | ||
} | ||
var es2018 = {}; | ||
var customError = createCommonjsModule(function (module, exports) { | ||
exports.CustomError = void 0; | ||
var customError = {}; | ||
customError.CustomError = void 0; | ||
class CustomError extends Error { | ||
@@ -113,26 +117,23 @@ get name() { | ||
} | ||
exports.CustomError = CustomError; | ||
//# sourceMappingURL=custom-error.js.map | ||
}); | ||
customError.CustomError = CustomError; | ||
var expectedError = createCommonjsModule(function (module, exports) { | ||
exports.ExpectedError = void 0; | ||
var expectedError = {}; | ||
class ExpectedError extends customError.CustomError { | ||
expectedError.ExpectedError = void 0; | ||
const custom_error_1$1 = customError; | ||
class ExpectedError extends custom_error_1$1.CustomError { | ||
} | ||
exports.ExpectedError = ExpectedError; | ||
//# sourceMappingURL=expected-error.js.map | ||
}); | ||
expectedError.ExpectedError = ExpectedError; | ||
var assertionError = createCommonjsModule(function (module, exports) { | ||
exports.AssertionError = void 0; | ||
var assertionError = {}; | ||
class AssertionError extends customError.CustomError { | ||
assertionError.AssertionError = void 0; | ||
const custom_error_1 = customError; | ||
class AssertionError extends custom_error_1.CustomError { | ||
} | ||
exports.AssertionError = AssertionError; | ||
//# sourceMappingURL=assertion-error.js.map | ||
}); | ||
assertionError.AssertionError = AssertionError; | ||
var normalize_1 = createCommonjsModule(function (module, exports) { | ||
exports.normalize = void 0; | ||
var normalize$1 = {}; | ||
normalize$1.normalize = void 0; | ||
function normalize(err) { | ||
@@ -146,29 +147,25 @@ var _a; | ||
} | ||
exports.normalize = normalize; | ||
//# sourceMappingURL=normalize.js.map | ||
}); | ||
normalize$1.normalize = normalize; | ||
var refute_1 = createCommonjsModule(function (module, exports) { | ||
exports.refute = void 0; | ||
var refute$1 = {}; | ||
refute$1.refute = void 0; | ||
const expected_error_1 = expectedError; | ||
function refute(condition, message) { | ||
if (condition) | ||
throw new expectedError.ExpectedError(message); | ||
throw new expected_error_1.ExpectedError(message); | ||
} | ||
exports.refute = refute; | ||
//# sourceMappingURL=refute.js.map | ||
}); | ||
refute$1.refute = refute; | ||
var assert_1 = createCommonjsModule(function (module, exports) { | ||
exports.assert = void 0; | ||
var assert$1 = {}; | ||
assert$1.assert = void 0; | ||
const assertion_error_1 = assertionError; | ||
function assert(condition, message) { | ||
if (!condition) | ||
throw new assertionError.AssertionError(message); | ||
throw new assertion_error_1.AssertionError(message); | ||
} | ||
exports.assert = assert; | ||
//# sourceMappingURL=assert.js.map | ||
}); | ||
assert$1.assert = assert; | ||
var es2018 = createCommonjsModule(function (module, exports) { | ||
(function (exports) { | ||
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -186,7 +183,7 @@ if (k2 === undefined) k2 = k; | ||
__exportStar(assertionError, exports); | ||
__exportStar(normalize_1, exports); | ||
__exportStar(refute_1, exports); | ||
__exportStar(assert_1, exports); | ||
__exportStar(normalize$1, exports); | ||
__exportStar(refute$1, exports); | ||
__exportStar(assert$1, exports); | ||
//# sourceMappingURL=index.js.map | ||
}); | ||
}(es2018)); | ||
@@ -229,5 +226,68 @@ var _items; | ||
var _limit, _map; | ||
class LRU { | ||
constructor(limit) { | ||
_limit.set(this, void 0); | ||
_map.set(this, new Map()); | ||
es2018.assert(Number.isInteger(limit), 'The parameter limit must be an integer'); | ||
es2018.assert(limit > 0, 'The parameter limit must be a positive value'); | ||
__classPrivateFieldSet(this, _limit, limit); | ||
} | ||
set(key, val) { | ||
if (__classPrivateFieldGet(this, _map).has(key)) { | ||
this.updateItem(key, val); | ||
} | ||
else { | ||
if (__classPrivateFieldGet(this, _map).size === __classPrivateFieldGet(this, _limit)) { | ||
__classPrivateFieldGet(this, _map).delete(this.getOldestKey()); | ||
} | ||
__classPrivateFieldGet(this, _map).set(key, val); | ||
} | ||
} | ||
has(key) { | ||
return __classPrivateFieldGet(this, _map).has(key); | ||
} | ||
/** | ||
* @throws NotFound | ||
*/ | ||
get(key) { | ||
if (!__classPrivateFieldGet(this, _map).has(key)) | ||
throw new Error(''); | ||
const val = __classPrivateFieldGet(this, _map).get(key); | ||
this.updateItem(key, val); | ||
return val; | ||
} | ||
tryGet(key) { | ||
try { | ||
return this.get(key); | ||
} | ||
catch (e) { | ||
if (e instanceof NotFound) | ||
return undefined; | ||
throw e; | ||
} | ||
} | ||
/** | ||
* Reinsert the item. | ||
*/ | ||
updateItem(key, val) { | ||
__classPrivateFieldGet(this, _map).delete(key); | ||
__classPrivateFieldGet(this, _map).set(key, val); | ||
} | ||
/** | ||
* Return the earliest key inserted in the Map | ||
*/ | ||
getOldestKey() { | ||
return __classPrivateFieldGet(this, _map).keys().next().value; | ||
} | ||
} | ||
_limit = new WeakMap(), _map = new WeakMap(); | ||
class NotFound extends es2018.CustomError { | ||
} | ||
exports.Emitter = Emitter; | ||
exports.EmptyQueueError = EmptyQueueError; | ||
exports.HashSet = HashSet; | ||
exports.LRU = LRU; | ||
exports.NotFound = NotFound; | ||
exports.Queue = Queue; | ||
@@ -234,0 +294,0 @@ exports.convertConsToArray = convertConsToArray; |
@@ -16,3 +16,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Structures={})}(this,(function(e){"use strict"; | ||
***************************************************************************** */ | ||
function t(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}var r,s;r=new WeakMap;class n{constructor(e){this.hash=e,s.set(this,new Map)}add(e){return t(this,s).set(this.hash(e),e),this}delete(e){return t(this,s).delete(this.hash(e))}has(e){return t(this,s).has(this.hash(e))}clear(){t(this,s).clear()}values(){return t(this,s).values()}get size(){return t(this,s).size}get[(s=new WeakMap,Symbol.toStringTag)](){return this.constructor.name}[Symbol.iterator](){return t(this,s).values()}}var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(e){var t={exports:{}};return e(t,t.exports),t.exports}var u,a=i((function(e,t){t.CustomError=void 0;class r extends Error{get name(){return this.constructor.name}}t.CustomError=r})),h=i((function(e,t){t.ExpectedError=void 0;class r extends a.CustomError{}t.ExpectedError=r})),c=i((function(e,t){t.AssertionError=void 0;class r extends a.CustomError{}t.AssertionError=r})),f=i((function(e,t){t.normalize=void 0,t.normalize=function(e){var t;return{name:e.name,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}}})),l=i((function(e,t){t.refute=void 0,t.refute=function(e,t){if(e)throw new h.ExpectedError(t)}})),d=i((function(e,t){t.assert=void 0,t.assert=function(e,t){if(!e)throw new c.AssertionError(t)}})),p=i((function(e,t){var r=o&&o.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),s=o&&o.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};s(a,t),s(h,t),s(c,t),s(f,t),s(l,t),s(d,t)}));u=new WeakMap;class m extends p.CustomError{constructor(){super("Queue is empty.")}}e.Emitter=class{constructor(){r.set(this,new Map)}on(e,s){t(this,r).has(e)||t(this,r).set(e,new Set);t(this,r).get(e).add(s)}off(e,s){if(t(this,r).has(e)){const n=t(this,r).get(e);n.delete(s),0===n.size&&t(this,r).delete(e)}}emit(e,s){if(t(this,r).has(e)){t(this,r).get(e).forEach((e=>e(s)))}}},e.EmptyQueueError=m,e.HashSet=n,e.Queue=class{constructor(){u.set(this,[])}empty(){t(this,u).length=0}enqueue(...e){t(this,u).push(...e)}dequeue(){if(0===this.size)throw new m;return t(this,u).shift()}get size(){return t(this,u).length}remove(e){let r;for(;(r=t(this,u).indexOf(e))>=0;)t(this,u).splice(r,1)}},e.convertConsToArray=function e([t,r]){return null===r?[t]:[t,...e(r)]},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
function t(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)}var r,s;r=new WeakMap;class i{constructor(e){this.hash=e,s.set(this,new Map)}add(e){return t(this,s).set(this.hash(e),e),this}delete(e){return t(this,s).delete(this.hash(e))}has(e){return t(this,s).has(this.hash(e))}clear(){t(this,s).clear()}values(){return t(this,s).values()}get size(){return t(this,s).size}get[(s=new WeakMap,Symbol.toStringTag)](){return this.constructor.name}[Symbol.iterator](){return t(this,s).values()}}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o={},a={CustomError:void 0};class h extends Error{get name(){return this.constructor.name}}a.CustomError=h;var u={ExpectedError:void 0};const c=a;class l extends c.CustomError{}u.ExpectedError=l;var d={AssertionError:void 0};const f=a;class p extends f.CustomError{}d.AssertionError=p;var m={};m.normalize=void 0,m.normalize=function(e){var t;return{name:e.name,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}};var w={refute:void 0};const v=u;w.refute=function(e,t){if(e)throw new v.ExpectedError(t)};var g={assert:void 0};const y=d;var E,b,x;g.assert=function(e,t){if(!e)throw new y.AssertionError(t)},function(e){var t=n&&n.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),r=n&&n.__exportStar||function(e,r){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(r,s)||t(r,e,s)};r(a,e),r(u,e),r(d,e),r(m,e),r(w,e),r(g,e)}(o);E=new WeakMap;class T extends o.CustomError{constructor(){super("Queue is empty.")}}b=new WeakMap,x=new WeakMap;class C extends o.CustomError{}e.Emitter=class{constructor(){r.set(this,new Map)}on(e,s){t(this,r).has(e)||t(this,r).set(e,new Set);t(this,r).get(e).add(s)}off(e,s){if(t(this,r).has(e)){const i=t(this,r).get(e);i.delete(s),0===i.size&&t(this,r).delete(e)}}emit(e,s){if(t(this,r).has(e)){t(this,r).get(e).forEach((e=>e(s)))}}},e.EmptyQueueError=T,e.HashSet=i,e.LRU=class{constructor(e){b.set(this,void 0),x.set(this,new Map),o.assert(Number.isInteger(e),"The parameter limit must be an integer"),o.assert(e>0,"The parameter limit must be a positive value"),function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?i.call(e,r):i?i.value=r:t.set(e,r)}(this,b,e)}set(e,r){t(this,x).has(e)?this.updateItem(e,r):(t(this,x).size===t(this,b)&&t(this,x).delete(this.getOldestKey()),t(this,x).set(e,r))}has(e){return t(this,x).has(e)}get(e){if(!t(this,x).has(e))throw new Error("");const r=t(this,x).get(e);return this.updateItem(e,r),r}tryGet(e){try{return this.get(e)}catch(e){if(e instanceof C)return;throw e}}updateItem(e,r){t(this,x).delete(e),t(this,x).set(e,r)}getOldestKey(){return t(this,x).keys().next().value}},e.NotFound=C,e.Queue=class{constructor(){E.set(this,[])}empty(){t(this,E).length=0}enqueue(...e){t(this,E).push(...e)}dequeue(){if(0===this.size)throw new T;return t(this,E).shift()}get size(){return t(this,E).length}remove(e){let r;for(;(r=t(this,E).indexOf(e))>=0;)t(this,E).splice(r,1)}},e.convertConsToArray=function e([t,r]){return null===r?[t]:[t,...e(r)]},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -28,31 +28,37 @@ (function (global, factory) { | ||
function __classPrivateFieldGet(receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
function __classPrivateFieldGet(receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
} | ||
var _map$1; | ||
function __classPrivateFieldSet(receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
} | ||
var _map$2; | ||
class Emitter { | ||
constructor() { | ||
_map$1.set(this, new Map()); | ||
_map$2.set(this, new Map()); | ||
} | ||
on(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map$1).has(event)) | ||
__classPrivateFieldGet(this, _map$1).set(event, new Set()); | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (!__classPrivateFieldGet(this, _map$2).has(event)) | ||
__classPrivateFieldGet(this, _map$2).set(event, new Set()); | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.add(handler); | ||
} | ||
off(event, handler) { | ||
if (__classPrivateFieldGet(this, _map$1).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (__classPrivateFieldGet(this, _map$2).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.delete(handler); | ||
if (set.size === 0) | ||
__classPrivateFieldGet(this, _map$1).delete(event); | ||
__classPrivateFieldGet(this, _map$2).delete(event); | ||
} | ||
} | ||
emit(event, value) { | ||
if (__classPrivateFieldGet(this, _map$1).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$1).get(event); | ||
if (__classPrivateFieldGet(this, _map$2).has(event)) { | ||
const set = __classPrivateFieldGet(this, _map$2).get(event); | ||
set.forEach(cb => cb(value)); | ||
@@ -62,34 +68,34 @@ } | ||
} | ||
_map$1 = new WeakMap(); | ||
_map$2 = new WeakMap(); | ||
var _map; | ||
var _map$1; | ||
class HashSet { | ||
constructor(hash) { | ||
this.hash = hash; | ||
_map.set(this, new Map()); | ||
_map$1.set(this, new Map()); | ||
} | ||
add(value) { | ||
__classPrivateFieldGet(this, _map).set(this.hash(value), value); | ||
__classPrivateFieldGet(this, _map$1).set(this.hash(value), value); | ||
return this; | ||
} | ||
delete(value) { | ||
return __classPrivateFieldGet(this, _map).delete(this.hash(value)); | ||
return __classPrivateFieldGet(this, _map$1).delete(this.hash(value)); | ||
} | ||
has(value) { | ||
return __classPrivateFieldGet(this, _map).has(this.hash(value)); | ||
return __classPrivateFieldGet(this, _map$1).has(this.hash(value)); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _map$1).clear(); | ||
} | ||
values() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _map$1).values(); | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _map$1).size; | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_map$1 = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
[Symbol.iterator]() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _map$1).values(); | ||
} | ||
@@ -100,9 +106,7 @@ } | ||
function createCommonjsModule(fn) { | ||
var module = { exports: {} }; | ||
return fn(module, module.exports), module.exports; | ||
} | ||
var es2018 = {}; | ||
var customError = createCommonjsModule(function (module, exports) { | ||
exports.CustomError = void 0; | ||
var customError = {}; | ||
customError.CustomError = void 0; | ||
class CustomError extends Error { | ||
@@ -113,26 +117,23 @@ get name() { | ||
} | ||
exports.CustomError = CustomError; | ||
//# sourceMappingURL=custom-error.js.map | ||
}); | ||
customError.CustomError = CustomError; | ||
var expectedError = createCommonjsModule(function (module, exports) { | ||
exports.ExpectedError = void 0; | ||
var expectedError = {}; | ||
class ExpectedError extends customError.CustomError { | ||
expectedError.ExpectedError = void 0; | ||
const custom_error_1$1 = customError; | ||
class ExpectedError extends custom_error_1$1.CustomError { | ||
} | ||
exports.ExpectedError = ExpectedError; | ||
//# sourceMappingURL=expected-error.js.map | ||
}); | ||
expectedError.ExpectedError = ExpectedError; | ||
var assertionError = createCommonjsModule(function (module, exports) { | ||
exports.AssertionError = void 0; | ||
var assertionError = {}; | ||
class AssertionError extends customError.CustomError { | ||
assertionError.AssertionError = void 0; | ||
const custom_error_1 = customError; | ||
class AssertionError extends custom_error_1.CustomError { | ||
} | ||
exports.AssertionError = AssertionError; | ||
//# sourceMappingURL=assertion-error.js.map | ||
}); | ||
assertionError.AssertionError = AssertionError; | ||
var normalize_1 = createCommonjsModule(function (module, exports) { | ||
exports.normalize = void 0; | ||
var normalize$1 = {}; | ||
normalize$1.normalize = void 0; | ||
function normalize(err) { | ||
@@ -146,29 +147,25 @@ var _a; | ||
} | ||
exports.normalize = normalize; | ||
//# sourceMappingURL=normalize.js.map | ||
}); | ||
normalize$1.normalize = normalize; | ||
var refute_1 = createCommonjsModule(function (module, exports) { | ||
exports.refute = void 0; | ||
var refute$1 = {}; | ||
refute$1.refute = void 0; | ||
const expected_error_1 = expectedError; | ||
function refute(condition, message) { | ||
if (condition) | ||
throw new expectedError.ExpectedError(message); | ||
throw new expected_error_1.ExpectedError(message); | ||
} | ||
exports.refute = refute; | ||
//# sourceMappingURL=refute.js.map | ||
}); | ||
refute$1.refute = refute; | ||
var assert_1 = createCommonjsModule(function (module, exports) { | ||
exports.assert = void 0; | ||
var assert$1 = {}; | ||
assert$1.assert = void 0; | ||
const assertion_error_1 = assertionError; | ||
function assert(condition, message) { | ||
if (!condition) | ||
throw new assertionError.AssertionError(message); | ||
throw new assertion_error_1.AssertionError(message); | ||
} | ||
exports.assert = assert; | ||
//# sourceMappingURL=assert.js.map | ||
}); | ||
assert$1.assert = assert; | ||
var es2018 = createCommonjsModule(function (module, exports) { | ||
(function (exports) { | ||
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -186,7 +183,7 @@ if (k2 === undefined) k2 = k; | ||
__exportStar(assertionError, exports); | ||
__exportStar(normalize_1, exports); | ||
__exportStar(refute_1, exports); | ||
__exportStar(assert_1, exports); | ||
__exportStar(normalize$1, exports); | ||
__exportStar(refute$1, exports); | ||
__exportStar(assert$1, exports); | ||
//# sourceMappingURL=index.js.map | ||
}); | ||
}(es2018)); | ||
@@ -229,5 +226,68 @@ var _items; | ||
var _limit, _map; | ||
class LRU { | ||
constructor(limit) { | ||
_limit.set(this, void 0); | ||
_map.set(this, new Map()); | ||
es2018.assert(Number.isInteger(limit), 'The parameter limit must be an integer'); | ||
es2018.assert(limit > 0, 'The parameter limit must be a positive value'); | ||
__classPrivateFieldSet(this, _limit, limit); | ||
} | ||
set(key, val) { | ||
if (__classPrivateFieldGet(this, _map).has(key)) { | ||
this.updateItem(key, val); | ||
} | ||
else { | ||
if (__classPrivateFieldGet(this, _map).size === __classPrivateFieldGet(this, _limit)) { | ||
__classPrivateFieldGet(this, _map).delete(this.getOldestKey()); | ||
} | ||
__classPrivateFieldGet(this, _map).set(key, val); | ||
} | ||
} | ||
has(key) { | ||
return __classPrivateFieldGet(this, _map).has(key); | ||
} | ||
/** | ||
* @throws NotFound | ||
*/ | ||
get(key) { | ||
if (!__classPrivateFieldGet(this, _map).has(key)) | ||
throw new Error(''); | ||
const val = __classPrivateFieldGet(this, _map).get(key); | ||
this.updateItem(key, val); | ||
return val; | ||
} | ||
tryGet(key) { | ||
try { | ||
return this.get(key); | ||
} | ||
catch (e) { | ||
if (e instanceof NotFound) | ||
return undefined; | ||
throw e; | ||
} | ||
} | ||
/** | ||
* Reinsert the item. | ||
*/ | ||
updateItem(key, val) { | ||
__classPrivateFieldGet(this, _map).delete(key); | ||
__classPrivateFieldGet(this, _map).set(key, val); | ||
} | ||
/** | ||
* Return the earliest key inserted in the Map | ||
*/ | ||
getOldestKey() { | ||
return __classPrivateFieldGet(this, _map).keys().next().value; | ||
} | ||
} | ||
_limit = new WeakMap(), _map = new WeakMap(); | ||
class NotFound extends es2018.CustomError { | ||
} | ||
exports.Emitter = Emitter; | ||
exports.EmptyQueueError = EmptyQueueError; | ||
exports.HashSet = HashSet; | ||
exports.LRU = LRU; | ||
exports.NotFound = NotFound; | ||
exports.Queue = Queue; | ||
@@ -234,0 +294,0 @@ exports.convertConsToArray = convertConsToArray; |
@@ -16,3 +16,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Structures={})}(this,(function(e){"use strict"; | ||
***************************************************************************** */ | ||
function t(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)}var r,s;r=new WeakMap;class n{constructor(e){this.hash=e,s.set(this,new Map)}add(e){return t(this,s).set(this.hash(e),e),this}delete(e){return t(this,s).delete(this.hash(e))}has(e){return t(this,s).has(this.hash(e))}clear(){t(this,s).clear()}values(){return t(this,s).values()}get size(){return t(this,s).size}get[(s=new WeakMap,Symbol.toStringTag)](){return this.constructor.name}[Symbol.iterator](){return t(this,s).values()}}var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(e){var t={exports:{}};return e(t,t.exports),t.exports}var u,a=i((function(e,t){t.CustomError=void 0;class r extends Error{get name(){return this.constructor.name}}t.CustomError=r})),h=i((function(e,t){t.ExpectedError=void 0;class r extends a.CustomError{}t.ExpectedError=r})),c=i((function(e,t){t.AssertionError=void 0;class r extends a.CustomError{}t.AssertionError=r})),f=i((function(e,t){t.normalize=void 0,t.normalize=function(e){var t;return{name:e.name,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}}})),l=i((function(e,t){t.refute=void 0,t.refute=function(e,t){if(e)throw new h.ExpectedError(t)}})),d=i((function(e,t){t.assert=void 0,t.assert=function(e,t){if(!e)throw new c.AssertionError(t)}})),p=i((function(e,t){var r=o&&o.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),s=o&&o.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};s(a,t),s(h,t),s(c,t),s(f,t),s(l,t),s(d,t)}));u=new WeakMap;class m extends p.CustomError{constructor(){super("Queue is empty.")}}e.Emitter=class{constructor(){r.set(this,new Map)}on(e,s){t(this,r).has(e)||t(this,r).set(e,new Set);t(this,r).get(e).add(s)}off(e,s){if(t(this,r).has(e)){const n=t(this,r).get(e);n.delete(s),0===n.size&&t(this,r).delete(e)}}emit(e,s){if(t(this,r).has(e)){t(this,r).get(e).forEach((e=>e(s)))}}},e.EmptyQueueError=m,e.HashSet=n,e.Queue=class{constructor(){u.set(this,[])}empty(){t(this,u).length=0}enqueue(...e){t(this,u).push(...e)}dequeue(){if(0===this.size)throw new m;return t(this,u).shift()}get size(){return t(this,u).length}remove(e){let r;for(;(r=t(this,u).indexOf(e))>=0;)t(this,u).splice(r,1)}},e.convertConsToArray=function e([t,r]){return null===r?[t]:[t,...e(r)]},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
function t(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)}var r,s;r=new WeakMap;class i{constructor(e){this.hash=e,s.set(this,new Map)}add(e){return t(this,s).set(this.hash(e),e),this}delete(e){return t(this,s).delete(this.hash(e))}has(e){return t(this,s).has(this.hash(e))}clear(){t(this,s).clear()}values(){return t(this,s).values()}get size(){return t(this,s).size}get[(s=new WeakMap,Symbol.toStringTag)](){return this.constructor.name}[Symbol.iterator](){return t(this,s).values()}}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o={},a={CustomError:void 0};class h extends Error{get name(){return this.constructor.name}}a.CustomError=h;var u={ExpectedError:void 0};const c=a;class l extends c.CustomError{}u.ExpectedError=l;var d={AssertionError:void 0};const f=a;class p extends f.CustomError{}d.AssertionError=p;var m={};m.normalize=void 0,m.normalize=function(e){var t;return{name:e.name,message:e.message,stack:null!==(t=e.stack)&&void 0!==t?t:null}};var w={refute:void 0};const v=u;w.refute=function(e,t){if(e)throw new v.ExpectedError(t)};var g={assert:void 0};const y=d;var E,b,x;g.assert=function(e,t){if(!e)throw new y.AssertionError(t)},function(e){var t=n&&n.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),r=n&&n.__exportStar||function(e,r){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(r,s)||t(r,e,s)};r(a,e),r(u,e),r(d,e),r(m,e),r(w,e),r(g,e)}(o);E=new WeakMap;class T extends o.CustomError{constructor(){super("Queue is empty.")}}b=new WeakMap,x=new WeakMap;class C extends o.CustomError{}e.Emitter=class{constructor(){r.set(this,new Map)}on(e,s){t(this,r).has(e)||t(this,r).set(e,new Set);t(this,r).get(e).add(s)}off(e,s){if(t(this,r).has(e)){const i=t(this,r).get(e);i.delete(s),0===i.size&&t(this,r).delete(e)}}emit(e,s){if(t(this,r).has(e)){t(this,r).get(e).forEach((e=>e(s)))}}},e.EmptyQueueError=T,e.HashSet=i,e.LRU=class{constructor(e){b.set(this,void 0),x.set(this,new Map),o.assert(Number.isInteger(e),"The parameter limit must be an integer"),o.assert(e>0,"The parameter limit must be a positive value"),function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?i.call(e,r):i?i.value=r:t.set(e,r)}(this,b,e)}set(e,r){t(this,x).has(e)?this.updateItem(e,r):(t(this,x).size===t(this,b)&&t(this,x).delete(this.getOldestKey()),t(this,x).set(e,r))}has(e){return t(this,x).has(e)}get(e){if(!t(this,x).has(e))throw new Error("");const r=t(this,x).get(e);return this.updateItem(e,r),r}tryGet(e){try{return this.get(e)}catch(e){if(e instanceof C)return;throw e}}updateItem(e,r){t(this,x).delete(e),t(this,x).set(e,r)}getOldestKey(){return t(this,x).keys().next().value}},e.NotFound=C,e.Queue=class{constructor(){E.set(this,[])}empty(){t(this,E).length=0}enqueue(...e){t(this,E).push(...e)}dequeue(){if(0===this.size)throw new T;return t(this,E).shift()}get size(){return t(this,E).length}remove(e){let r;for(;(r=t(this,E).indexOf(e))>=0;)t(this,E).splice(r,1)}},e.convertConsToArray=function e([t,r]){return null===r?[t]:[t,...e(r)]},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -5,1 +5,2 @@ export * from './cons'; | ||
export * from './queue'; | ||
export * from './lru'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
__exportStar(require("./queue"), exports); | ||
__exportStar(require("./lru"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -5,1 +5,2 @@ export * from './cons'; | ||
export * from './queue'; | ||
export * from './lru'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
__exportStar(require("./queue"), exports); | ||
__exportStar(require("./lru"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@blackglory/structures", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "", | ||
@@ -43,26 +43,26 @@ "files": [ | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@rollup/plugin-replace": "^2.4.1", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.35", | ||
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"@typescript-eslint/parser": "^4.18.0", | ||
"eslint": "^7.22.0", | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-replace": "^2.4.2", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^15.3.0", | ||
"@typescript-eslint/eslint-plugin": "^4.23.0", | ||
"@typescript-eslint/parser": "^4.23.0", | ||
"eslint": "^7.26.0", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"npm-run-all": "^4.1.5", | ||
"return-style": "^0.12.2", | ||
"return-style": "^0.12.3", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.41.2", | ||
"rollup": "^2.48.0", | ||
"rollup-plugin-analyzer": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"standard-version": "^9.1.1", | ||
"ts-jest": "^26.5.3", | ||
"standard-version": "^9.3.0", | ||
"ts-jest": "^26.5.6", | ||
"tscpaths": "^0.0.9", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.2.3" | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
}, | ||
@@ -69,0 +69,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
292120
56
1688