@valkyriestudios/utils 12.49.0 → 12.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/caching/LRU.js +29 -21
- package/esm/caching/LRU.js +29 -21
- package/package.json +6 -6
package/cjs/caching/LRU.js
CHANGED
|
@@ -26,7 +26,7 @@ class LRUCache {
|
|
|
26
26
|
_LRUCache_max_size.set(this, void 0);
|
|
27
27
|
_LRUCache_size.set(this, 0);
|
|
28
28
|
const { max_size = 100 } = (0, is_1.default)(opts) ? opts : {};
|
|
29
|
-
__classPrivateFieldSet(this, _LRUCache_map,
|
|
29
|
+
__classPrivateFieldSet(this, _LRUCache_map, new Map(), "f");
|
|
30
30
|
__classPrivateFieldSet(this, _LRUCache_max_size, (0, isIntegerAbove_1.default)(max_size, 0) ? max_size : 100, "f");
|
|
31
31
|
}
|
|
32
32
|
get max_size() {
|
|
@@ -40,43 +40,51 @@ class LRUCache {
|
|
|
40
40
|
this.evictTail();
|
|
41
41
|
}
|
|
42
42
|
has(key) {
|
|
43
|
-
return
|
|
43
|
+
return __classPrivateFieldGet(this, _LRUCache_map, "f").has(key);
|
|
44
44
|
}
|
|
45
45
|
get(key) {
|
|
46
|
-
const node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
47
|
-
if (
|
|
46
|
+
const node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
47
|
+
if (node === undefined)
|
|
48
48
|
return undefined;
|
|
49
|
-
this
|
|
49
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== node)
|
|
50
|
+
this.moveToFront(node);
|
|
50
51
|
return node.value;
|
|
51
52
|
}
|
|
52
53
|
set(key, value) {
|
|
53
54
|
var _a;
|
|
54
|
-
let node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
55
|
+
let node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
55
56
|
if (node !== undefined) {
|
|
56
57
|
node.value = value;
|
|
58
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== node) {
|
|
59
|
+
this.moveToFront(node);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (__classPrivateFieldGet(this, _LRUCache_size, "f") >= __classPrivateFieldGet(this, _LRUCache_max_size, "f") && __classPrivateFieldGet(this, _LRUCache_tail, "f") !== null) {
|
|
63
|
+
node = __classPrivateFieldGet(this, _LRUCache_tail, "f");
|
|
64
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(node.key);
|
|
65
|
+
node.key = key;
|
|
66
|
+
node.value = value;
|
|
67
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").set(key, node);
|
|
57
68
|
this.moveToFront(node);
|
|
58
69
|
}
|
|
59
70
|
else {
|
|
60
71
|
node = { key, value, prev: null, next: null };
|
|
61
|
-
__classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
72
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").set(key, node);
|
|
62
73
|
this.addToFront(node);
|
|
63
74
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a++, _a), "f");
|
|
64
|
-
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") && __classPrivateFieldGet(this, _LRUCache_size, "f") > __classPrivateFieldGet(this, _LRUCache_max_size, "f")) {
|
|
65
|
-
this.evictTail();
|
|
66
|
-
}
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
del(key) {
|
|
70
78
|
var _a;
|
|
71
|
-
const node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
72
|
-
if (
|
|
79
|
+
const node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
80
|
+
if (node === undefined)
|
|
73
81
|
return;
|
|
74
82
|
this.removeNode(node);
|
|
75
|
-
|
|
83
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(key);
|
|
76
84
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
|
|
77
85
|
}
|
|
78
86
|
clear() {
|
|
79
|
-
|
|
87
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").clear();
|
|
80
88
|
__classPrivateFieldSet(this, _LRUCache_head, null, "f");
|
|
81
89
|
__classPrivateFieldSet(this, _LRUCache_tail, null, "f");
|
|
82
90
|
__classPrivateFieldSet(this, _LRUCache_size, 0, "f");
|
|
@@ -84,20 +92,20 @@ class LRUCache {
|
|
|
84
92
|
addToFront(node) {
|
|
85
93
|
node.next = __classPrivateFieldGet(this, _LRUCache_head, "f");
|
|
86
94
|
node.prev = null;
|
|
87
|
-
if (__classPrivateFieldGet(this, _LRUCache_head, "f")) {
|
|
95
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== null) {
|
|
88
96
|
__classPrivateFieldGet(this, _LRUCache_head, "f").prev = node;
|
|
89
97
|
}
|
|
90
98
|
__classPrivateFieldSet(this, _LRUCache_head, node, "f");
|
|
91
|
-
if (
|
|
99
|
+
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") === null) {
|
|
92
100
|
__classPrivateFieldSet(this, _LRUCache_tail, node, "f");
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
removeNode(node) {
|
|
96
|
-
if (node.prev)
|
|
104
|
+
if (node.prev !== null)
|
|
97
105
|
node.prev.next = node.next;
|
|
98
106
|
else
|
|
99
107
|
__classPrivateFieldSet(this, _LRUCache_head, node.next, "f");
|
|
100
|
-
if (node.next)
|
|
108
|
+
if (node.next !== null)
|
|
101
109
|
node.next.prev = node.prev;
|
|
102
110
|
else
|
|
103
111
|
__classPrivateFieldSet(this, _LRUCache_tail, node.prev, "f");
|
|
@@ -105,16 +113,16 @@ class LRUCache {
|
|
|
105
113
|
node.next = null;
|
|
106
114
|
}
|
|
107
115
|
moveToFront(node) {
|
|
108
|
-
if (__classPrivateFieldGet(this, _LRUCache_head, "f") === node)
|
|
109
|
-
return;
|
|
110
116
|
this.removeNode(node);
|
|
111
117
|
this.addToFront(node);
|
|
112
118
|
}
|
|
113
119
|
evictTail() {
|
|
114
120
|
var _a;
|
|
121
|
+
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") === null)
|
|
122
|
+
return;
|
|
115
123
|
const old_tail = __classPrivateFieldGet(this, _LRUCache_tail, "f");
|
|
116
124
|
this.removeNode(old_tail);
|
|
117
|
-
|
|
125
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(old_tail.key);
|
|
118
126
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
|
|
119
127
|
}
|
|
120
128
|
}
|
package/esm/caching/LRU.js
CHANGED
|
@@ -20,7 +20,7 @@ class LRUCache {
|
|
|
20
20
|
_LRUCache_max_size.set(this, void 0);
|
|
21
21
|
_LRUCache_size.set(this, 0);
|
|
22
22
|
const { max_size = 100 } = isObject(opts) ? opts : {};
|
|
23
|
-
__classPrivateFieldSet(this, _LRUCache_map,
|
|
23
|
+
__classPrivateFieldSet(this, _LRUCache_map, new Map(), "f");
|
|
24
24
|
__classPrivateFieldSet(this, _LRUCache_max_size, isIntegerGt(max_size, 0) ? max_size : 100, "f");
|
|
25
25
|
}
|
|
26
26
|
get max_size() {
|
|
@@ -34,43 +34,51 @@ class LRUCache {
|
|
|
34
34
|
this.evictTail();
|
|
35
35
|
}
|
|
36
36
|
has(key) {
|
|
37
|
-
return
|
|
37
|
+
return __classPrivateFieldGet(this, _LRUCache_map, "f").has(key);
|
|
38
38
|
}
|
|
39
39
|
get(key) {
|
|
40
|
-
const node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
41
|
-
if (
|
|
40
|
+
const node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
41
|
+
if (node === undefined)
|
|
42
42
|
return undefined;
|
|
43
|
-
this
|
|
43
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== node)
|
|
44
|
+
this.moveToFront(node);
|
|
44
45
|
return node.value;
|
|
45
46
|
}
|
|
46
47
|
set(key, value) {
|
|
47
48
|
var _a;
|
|
48
|
-
let node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
49
|
+
let node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
49
50
|
if (node !== undefined) {
|
|
50
51
|
node.value = value;
|
|
52
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== node) {
|
|
53
|
+
this.moveToFront(node);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (__classPrivateFieldGet(this, _LRUCache_size, "f") >= __classPrivateFieldGet(this, _LRUCache_max_size, "f") && __classPrivateFieldGet(this, _LRUCache_tail, "f") !== null) {
|
|
57
|
+
node = __classPrivateFieldGet(this, _LRUCache_tail, "f");
|
|
58
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(node.key);
|
|
59
|
+
node.key = key;
|
|
60
|
+
node.value = value;
|
|
61
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").set(key, node);
|
|
51
62
|
this.moveToFront(node);
|
|
52
63
|
}
|
|
53
64
|
else {
|
|
54
65
|
node = { key, value, prev: null, next: null };
|
|
55
|
-
__classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
66
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").set(key, node);
|
|
56
67
|
this.addToFront(node);
|
|
57
68
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a++, _a), "f");
|
|
58
|
-
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") && __classPrivateFieldGet(this, _LRUCache_size, "f") > __classPrivateFieldGet(this, _LRUCache_max_size, "f")) {
|
|
59
|
-
this.evictTail();
|
|
60
|
-
}
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
del(key) {
|
|
64
72
|
var _a;
|
|
65
|
-
const node = __classPrivateFieldGet(this, _LRUCache_map, "f")
|
|
66
|
-
if (
|
|
73
|
+
const node = __classPrivateFieldGet(this, _LRUCache_map, "f").get(key);
|
|
74
|
+
if (node === undefined)
|
|
67
75
|
return;
|
|
68
76
|
this.removeNode(node);
|
|
69
|
-
|
|
77
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(key);
|
|
70
78
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
|
|
71
79
|
}
|
|
72
80
|
clear() {
|
|
73
|
-
|
|
81
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").clear();
|
|
74
82
|
__classPrivateFieldSet(this, _LRUCache_head, null, "f");
|
|
75
83
|
__classPrivateFieldSet(this, _LRUCache_tail, null, "f");
|
|
76
84
|
__classPrivateFieldSet(this, _LRUCache_size, 0, "f");
|
|
@@ -78,20 +86,20 @@ class LRUCache {
|
|
|
78
86
|
addToFront(node) {
|
|
79
87
|
node.next = __classPrivateFieldGet(this, _LRUCache_head, "f");
|
|
80
88
|
node.prev = null;
|
|
81
|
-
if (__classPrivateFieldGet(this, _LRUCache_head, "f")) {
|
|
89
|
+
if (__classPrivateFieldGet(this, _LRUCache_head, "f") !== null) {
|
|
82
90
|
__classPrivateFieldGet(this, _LRUCache_head, "f").prev = node;
|
|
83
91
|
}
|
|
84
92
|
__classPrivateFieldSet(this, _LRUCache_head, node, "f");
|
|
85
|
-
if (
|
|
93
|
+
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") === null) {
|
|
86
94
|
__classPrivateFieldSet(this, _LRUCache_tail, node, "f");
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
removeNode(node) {
|
|
90
|
-
if (node.prev)
|
|
98
|
+
if (node.prev !== null)
|
|
91
99
|
node.prev.next = node.next;
|
|
92
100
|
else
|
|
93
101
|
__classPrivateFieldSet(this, _LRUCache_head, node.next, "f");
|
|
94
|
-
if (node.next)
|
|
102
|
+
if (node.next !== null)
|
|
95
103
|
node.next.prev = node.prev;
|
|
96
104
|
else
|
|
97
105
|
__classPrivateFieldSet(this, _LRUCache_tail, node.prev, "f");
|
|
@@ -99,16 +107,16 @@ class LRUCache {
|
|
|
99
107
|
node.next = null;
|
|
100
108
|
}
|
|
101
109
|
moveToFront(node) {
|
|
102
|
-
if (__classPrivateFieldGet(this, _LRUCache_head, "f") === node)
|
|
103
|
-
return;
|
|
104
110
|
this.removeNode(node);
|
|
105
111
|
this.addToFront(node);
|
|
106
112
|
}
|
|
107
113
|
evictTail() {
|
|
108
114
|
var _a;
|
|
115
|
+
if (__classPrivateFieldGet(this, _LRUCache_tail, "f") === null)
|
|
116
|
+
return;
|
|
109
117
|
const old_tail = __classPrivateFieldGet(this, _LRUCache_tail, "f");
|
|
110
118
|
this.removeNode(old_tail);
|
|
111
|
-
|
|
119
|
+
__classPrivateFieldGet(this, _LRUCache_map, "f").delete(old_tail.key);
|
|
112
120
|
__classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
|
|
113
121
|
}
|
|
114
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valkyriestudios/utils",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.50.0",
|
|
4
4
|
"description": "A collection of single-function utilities for common tasks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Vermeulen",
|
|
@@ -609,12 +609,12 @@
|
|
|
609
609
|
}
|
|
610
610
|
},
|
|
611
611
|
"devDependencies": {
|
|
612
|
-
"@types/node": "^22.19.
|
|
613
|
-
"@vitest/coverage-v8": "^4.
|
|
612
|
+
"@types/node": "^22.19.15",
|
|
613
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
614
614
|
"esbuild-register": "^3.6.0",
|
|
615
|
-
"eslint": "^9.39.
|
|
615
|
+
"eslint": "^9.39.4",
|
|
616
616
|
"typescript": "^5.9.3",
|
|
617
|
-
"typescript-eslint": "^8.
|
|
618
|
-
"vitest": "^4.
|
|
617
|
+
"typescript-eslint": "^8.57.2",
|
|
618
|
+
"vitest": "^4.1.2"
|
|
619
619
|
}
|
|
620
620
|
}
|