@blackglory/structures
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -5,2 +5,4 @@ # Changelog | ||
### [0.2.2](https://github.com/BlackGlory/structures/compare/v0.2.1...v0.2.2) (2021-07-04) | ||
### [0.2.1](https://github.com/BlackGlory/structures/compare/v0.2.0...v0.2.1) (2021-05-16) | ||
@@ -7,0 +9,0 @@ |
@@ -1,3 +0,4 @@ | ||
export declare type Cons<T> = [T, Cons<T>] | [T, null]; | ||
import { Cons } from 'justypes'; | ||
export { Cons } from 'justypes'; | ||
export declare function convertConsToArray<T>([value, next]: Cons<T>): T[]; | ||
export declare function convertArrayToCons<T>([value, ...next]: T[]): Cons<T>; |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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; | ||
var _Emitter_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,27 +12,27 @@ exports.Emitter = void 0; | ||
constructor() { | ||
_map.set(this, new Map()); | ||
_Emitter_map.set(this, new Map()); | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_Emitter_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
on(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) { | ||
__classPrivateFieldGet(this, _map).set(event, new Set()); | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) { | ||
__classPrivateFieldGet(this, _Emitter_map, "f").set(event, new Set()); | ||
} | ||
const set = __classPrivateFieldGet(this, _map).get(event); | ||
const set = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
set.add(handler); | ||
} | ||
off(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) | ||
return; | ||
const handlers = __classPrivateFieldGet(this, _map).get(event); | ||
const handlers = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
handlers.delete(handler); | ||
if (handlers.size === 0) { | ||
__classPrivateFieldGet(this, _map).delete(event); | ||
__classPrivateFieldGet(this, _Emitter_map, "f").delete(event); | ||
} | ||
} | ||
emit(event, value) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) | ||
return; | ||
const set = __classPrivateFieldGet(this, _map).get(event); | ||
const set = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
set.forEach(cb => cb(value)); | ||
@@ -40,0 +39,0 @@ } |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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; | ||
var _HashSet_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,28 +13,28 @@ exports.HashSet = void 0; | ||
this.hash = hash; | ||
_map.set(this, new Map()); | ||
_HashSet_map.set(this, new Map()); | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_HashSet_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").size; | ||
} | ||
[Symbol.iterator]() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").values(); | ||
} | ||
add(value) { | ||
__classPrivateFieldGet(this, _map).set(this.hash(value), value); | ||
__classPrivateFieldGet(this, _HashSet_map, "f").set(this.hash(value), value); | ||
return this; | ||
} | ||
delete(value) { | ||
return __classPrivateFieldGet(this, _map).delete(this.hash(value)); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").delete(this.hash(value)); | ||
} | ||
has(value) { | ||
return __classPrivateFieldGet(this, _map).has(this.hash(value)); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").has(this.hash(value)); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _HashSet_map, "f").clear(); | ||
} | ||
values() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").values(); | ||
} | ||
@@ -42,0 +41,0 @@ } |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _limit, _map; | ||
var _LRUMap_limit, _LRUMap_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,23 +19,23 @@ exports.LRUMap = void 0; | ||
constructor(limit) { | ||
_limit.set(this, void 0); | ||
_map.set(this, new Map()); | ||
_LRUMap_limit.set(this, void 0); | ||
_LRUMap_map.set(this, new Map()); | ||
errors_1.assert(Number.isInteger(limit), 'The parameter limit must be an integer'); | ||
errors_1.assert(limit > 0, 'The parameter limit must be a positive value'); | ||
__classPrivateFieldSet(this, _limit, limit); | ||
__classPrivateFieldSet(this, _LRUMap_limit, limit, "f"); | ||
} | ||
get [(_limit = new WeakMap(), _map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_LRUMap_limit = new WeakMap(), _LRUMap_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").size; | ||
} | ||
set(key, value) { | ||
if (__classPrivateFieldGet(this, _map).has(key)) { | ||
if (__classPrivateFieldGet(this, _LRUMap_map, "f").has(key)) { | ||
this.updateItem(key, value); | ||
} | ||
else { | ||
if (__classPrivateFieldGet(this, _map).size === __classPrivateFieldGet(this, _limit)) { | ||
__classPrivateFieldGet(this, _map).delete(this.getColdestKey()); | ||
if (__classPrivateFieldGet(this, _LRUMap_map, "f").size === __classPrivateFieldGet(this, _LRUMap_limit, "f")) { | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").delete(this.getColdestKey()); | ||
} | ||
__classPrivateFieldGet(this, _map).set(key, value); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value); | ||
} | ||
@@ -47,3 +45,3 @@ return this; | ||
has(key) { | ||
return __classPrivateFieldGet(this, _map).has(key); | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").has(key); | ||
} | ||
@@ -53,3 +51,3 @@ get(key) { | ||
return undefined; | ||
const value = __classPrivateFieldGet(this, _map).get(key); | ||
const value = __classPrivateFieldGet(this, _LRUMap_map, "f").get(key); | ||
this.updateItem(key, value); | ||
@@ -59,13 +57,13 @@ return value; | ||
delete(key) { | ||
return __classPrivateFieldGet(this, _map).delete(key); | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").delete(key); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").clear(); | ||
} | ||
updateItem(key, value) { | ||
__classPrivateFieldGet(this, _map).delete(key); | ||
__classPrivateFieldGet(this, _map).set(key, value); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").delete(key); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value); | ||
} | ||
getColdestKey() { | ||
return __classPrivateFieldGet(this, _map).keys().next().value; | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").keys().next().value; | ||
} | ||
@@ -72,0 +70,0 @@ } |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _items; | ||
var _Queue_items; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,23 +12,23 @@ exports.Queue = void 0; | ||
constructor() { | ||
_items.set(this, []); | ||
_Queue_items.set(this, []); | ||
} | ||
get [(_items = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_Queue_items = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _items).length; | ||
return __classPrivateFieldGet(this, _Queue_items, "f").length; | ||
} | ||
empty() { | ||
__classPrivateFieldGet(this, _items).length = 0; | ||
__classPrivateFieldGet(this, _Queue_items, "f").length = 0; | ||
} | ||
enqueue(...items) { | ||
__classPrivateFieldGet(this, _items).push(...items); | ||
__classPrivateFieldGet(this, _Queue_items, "f").push(...items); | ||
} | ||
dequeue() { | ||
return __classPrivateFieldGet(this, _items).shift(); | ||
return __classPrivateFieldGet(this, _Queue_items, "f").shift(); | ||
} | ||
remove(item) { | ||
let index; | ||
while ((index = __classPrivateFieldGet(this, _items).indexOf(item)) >= 0) { | ||
__classPrivateFieldGet(this, _items).splice(index, 1); | ||
while ((index = __classPrivateFieldGet(this, _Queue_items, "f").indexOf(item)) >= 0) { | ||
__classPrivateFieldGet(this, _Queue_items, "f").splice(index, 1); | ||
} | ||
@@ -36,0 +35,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { UnpackedIterable } from 'hotypes'; | ||
import { UnpackedIterable } from 'justypes'; | ||
export declare class TrieMap<K extends Iterable<T>, V, T = UnpackedIterable<K>> { | ||
@@ -3,0 +3,0 @@ #private; |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _root; | ||
var _TrieMap_root; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,9 +19,9 @@ exports.TrieMap = void 0; | ||
constructor() { | ||
_root.set(this, new TrieNode()); | ||
_TrieMap_root.set(this, new TrieNode()); | ||
} | ||
get [(_root = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_TrieMap_root = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
set(key, value) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -38,3 +37,3 @@ if (!node.children.has(part)) { | ||
has(key) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -51,3 +50,3 @@ if (node.children.has(part)) { | ||
get(key) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -65,3 +64,3 @@ if (node.children.has(part)) { | ||
const parentNodes = []; | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -68,0 +67,0 @@ if (node.children.has(part)) { |
@@ -1,3 +0,4 @@ | ||
export declare type Cons<T> = [T, Cons<T>] | [T, null]; | ||
import { Cons } from 'justypes'; | ||
export { Cons } from 'justypes'; | ||
export declare function convertConsToArray<T>([value, next]: Cons<T>): T[]; | ||
export declare function convertArrayToCons<T>([value, ...next]: T[]): Cons<T>; |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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; | ||
var _Emitter_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,27 +12,27 @@ exports.Emitter = void 0; | ||
constructor() { | ||
_map.set(this, new Map()); | ||
_Emitter_map.set(this, new Map()); | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_Emitter_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
on(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) { | ||
__classPrivateFieldGet(this, _map).set(event, new Set()); | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) { | ||
__classPrivateFieldGet(this, _Emitter_map, "f").set(event, new Set()); | ||
} | ||
const set = __classPrivateFieldGet(this, _map).get(event); | ||
const set = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
set.add(handler); | ||
} | ||
off(event, handler) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) | ||
return; | ||
const handlers = __classPrivateFieldGet(this, _map).get(event); | ||
const handlers = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
handlers.delete(handler); | ||
if (handlers.size === 0) { | ||
__classPrivateFieldGet(this, _map).delete(event); | ||
__classPrivateFieldGet(this, _Emitter_map, "f").delete(event); | ||
} | ||
} | ||
emit(event, value) { | ||
if (!__classPrivateFieldGet(this, _map).has(event)) | ||
if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) | ||
return; | ||
const set = __classPrivateFieldGet(this, _map).get(event); | ||
const set = __classPrivateFieldGet(this, _Emitter_map, "f").get(event); | ||
set.forEach(cb => cb(value)); | ||
@@ -40,0 +39,0 @@ } |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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; | ||
var _HashSet_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,28 +13,28 @@ exports.HashSet = void 0; | ||
this.hash = hash; | ||
_map.set(this, new Map()); | ||
_HashSet_map.set(this, new Map()); | ||
} | ||
get [(_map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_HashSet_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").size; | ||
} | ||
[Symbol.iterator]() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").values(); | ||
} | ||
add(value) { | ||
__classPrivateFieldGet(this, _map).set(this.hash(value), value); | ||
__classPrivateFieldGet(this, _HashSet_map, "f").set(this.hash(value), value); | ||
return this; | ||
} | ||
delete(value) { | ||
return __classPrivateFieldGet(this, _map).delete(this.hash(value)); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").delete(this.hash(value)); | ||
} | ||
has(value) { | ||
return __classPrivateFieldGet(this, _map).has(this.hash(value)); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").has(this.hash(value)); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _HashSet_map, "f").clear(); | ||
} | ||
values() { | ||
return __classPrivateFieldGet(this, _map).values(); | ||
return __classPrivateFieldGet(this, _HashSet_map, "f").values(); | ||
} | ||
@@ -42,0 +41,0 @@ } |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _limit, _map; | ||
var _LRUMap_limit, _LRUMap_map; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,23 +19,23 @@ exports.LRUMap = void 0; | ||
constructor(limit) { | ||
_limit.set(this, void 0); | ||
_map.set(this, new Map()); | ||
_LRUMap_limit.set(this, void 0); | ||
_LRUMap_map.set(this, new Map()); | ||
errors_1.assert(Number.isInteger(limit), 'The parameter limit must be an integer'); | ||
errors_1.assert(limit > 0, 'The parameter limit must be a positive value'); | ||
__classPrivateFieldSet(this, _limit, limit); | ||
__classPrivateFieldSet(this, _LRUMap_limit, limit, "f"); | ||
} | ||
get [(_limit = new WeakMap(), _map = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_LRUMap_limit = new WeakMap(), _LRUMap_map = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _map).size; | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").size; | ||
} | ||
set(key, value) { | ||
if (__classPrivateFieldGet(this, _map).has(key)) { | ||
if (__classPrivateFieldGet(this, _LRUMap_map, "f").has(key)) { | ||
this.updateItem(key, value); | ||
} | ||
else { | ||
if (__classPrivateFieldGet(this, _map).size === __classPrivateFieldGet(this, _limit)) { | ||
__classPrivateFieldGet(this, _map).delete(this.getColdestKey()); | ||
if (__classPrivateFieldGet(this, _LRUMap_map, "f").size === __classPrivateFieldGet(this, _LRUMap_limit, "f")) { | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").delete(this.getColdestKey()); | ||
} | ||
__classPrivateFieldGet(this, _map).set(key, value); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value); | ||
} | ||
@@ -47,3 +45,3 @@ return this; | ||
has(key) { | ||
return __classPrivateFieldGet(this, _map).has(key); | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").has(key); | ||
} | ||
@@ -53,3 +51,3 @@ get(key) { | ||
return undefined; | ||
const value = __classPrivateFieldGet(this, _map).get(key); | ||
const value = __classPrivateFieldGet(this, _LRUMap_map, "f").get(key); | ||
this.updateItem(key, value); | ||
@@ -59,13 +57,13 @@ return value; | ||
delete(key) { | ||
return __classPrivateFieldGet(this, _map).delete(key); | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").delete(key); | ||
} | ||
clear() { | ||
__classPrivateFieldGet(this, _map).clear(); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").clear(); | ||
} | ||
updateItem(key, value) { | ||
__classPrivateFieldGet(this, _map).delete(key); | ||
__classPrivateFieldGet(this, _map).set(key, value); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").delete(key); | ||
__classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value); | ||
} | ||
getColdestKey() { | ||
return __classPrivateFieldGet(this, _map).keys().next().value; | ||
return __classPrivateFieldGet(this, _LRUMap_map, "f").keys().next().value; | ||
} | ||
@@ -72,0 +70,0 @@ } |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _items; | ||
var _Queue_items; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,23 +12,23 @@ exports.Queue = void 0; | ||
constructor() { | ||
_items.set(this, []); | ||
_Queue_items.set(this, []); | ||
} | ||
get [(_items = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_Queue_items = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
get size() { | ||
return __classPrivateFieldGet(this, _items).length; | ||
return __classPrivateFieldGet(this, _Queue_items, "f").length; | ||
} | ||
empty() { | ||
__classPrivateFieldGet(this, _items).length = 0; | ||
__classPrivateFieldGet(this, _Queue_items, "f").length = 0; | ||
} | ||
enqueue(...items) { | ||
__classPrivateFieldGet(this, _items).push(...items); | ||
__classPrivateFieldGet(this, _Queue_items, "f").push(...items); | ||
} | ||
dequeue() { | ||
return __classPrivateFieldGet(this, _items).shift(); | ||
return __classPrivateFieldGet(this, _Queue_items, "f").shift(); | ||
} | ||
remove(item) { | ||
let index; | ||
while ((index = __classPrivateFieldGet(this, _items).indexOf(item)) >= 0) { | ||
__classPrivateFieldGet(this, _items).splice(index, 1); | ||
while ((index = __classPrivateFieldGet(this, _Queue_items, "f").indexOf(item)) >= 0) { | ||
__classPrivateFieldGet(this, _Queue_items, "f").splice(index, 1); | ||
} | ||
@@ -36,0 +35,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { UnpackedIterable } from 'hotypes'; | ||
import { UnpackedIterable } from 'justypes'; | ||
export declare class TrieMap<K extends Iterable<T>, V, T = UnpackedIterable<K>> { | ||
@@ -3,0 +3,0 @@ #private; |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (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 _root; | ||
var _TrieMap_root; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,9 +19,9 @@ exports.TrieMap = void 0; | ||
constructor() { | ||
_root.set(this, new TrieNode()); | ||
_TrieMap_root.set(this, new TrieNode()); | ||
} | ||
get [(_root = new WeakMap(), Symbol.toStringTag)]() { | ||
get [(_TrieMap_root = new WeakMap(), Symbol.toStringTag)]() { | ||
return this.constructor.name; | ||
} | ||
set(key, value) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -38,3 +37,3 @@ if (!node.children.has(part)) { | ||
has(key) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -51,3 +50,3 @@ if (node.children.has(part)) { | ||
get(key) { | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -65,3 +64,3 @@ if (node.children.has(part)) { | ||
const parentNodes = []; | ||
let node = __classPrivateFieldGet(this, _root); | ||
let node = __classPrivateFieldGet(this, _TrieMap_root, "f"); | ||
for (const part of key) { | ||
@@ -68,0 +67,0 @@ if (node.children.has(part)) { |
{ | ||
"name": "@blackglory/structures", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "", | ||
@@ -43,3 +43,3 @@ "files": [ | ||
"devDependencies": { | ||
"@blackglory/jest-matchers": "^0.1.17", | ||
"@blackglory/jest-matchers": "^0.1.19", | ||
"@commitlint/cli": "^12.1.4", | ||
@@ -53,24 +53,24 @@ "@commitlint/config-conventional": "^12.1.4", | ||
"@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", | ||
"@types/node": "^16.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.28.1", | ||
"@typescript-eslint/parser": "^4.28.1", | ||
"eslint": "^7.30.0", | ||
"husky": "^4.3.8", | ||
"iterable-operator": "^0.13.6", | ||
"jest": "^26.6.3", | ||
"iterable-operator": "^0.14.1", | ||
"jest": "^27.0.6", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.48.0", | ||
"rollup": "^2.52.7", | ||
"rollup-plugin-analyzer": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"standard-version": "^9.3.0", | ||
"ts-jest": "^26.5.6", | ||
"ts-jest": "^27.0.3", | ||
"tscpaths": "^0.0.9", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
"tslib": "^2.3.0", | ||
"typescript": "^4.3.5" | ||
}, | ||
"dependencies": { | ||
"@blackglory/errors": "^1.1.2", | ||
"hotypes": "^0.2.1" | ||
"justypes": "^0.1.5" | ||
} | ||
} |
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 too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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 too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
1640639
9864
1
+ Addedjustypes@^0.1.5
+ Addedjustypes@0.1.7(transitive)
- Removedhotypes@^0.2.1
- Removedhotypes@0.2.3(transitive)