This commit is contained in:
2025-11-11 00:04:55 -06:00
parent a76ad41fde
commit 40538eddfd
6405 changed files with 1289756 additions and 0 deletions

17
node_modules/sweet-collections/dist/map/LfuMap.d.ts generated vendored Normal file
View File

@ -0,0 +1,17 @@
import { SizedMap } from './SizedMap';
export declare class LfuMap<K, V> extends SizedMap<K, V> {
private queue;
private frequencies;
private leastFrequent;
has(key: K): boolean;
get(key: K, _default?: V): V | undefined;
set(key: K, value: V): this;
delete(key: K): boolean;
clear(): void;
private initQueue;
private queuePop;
private moveToTop;
private removeNode;
private increaseFrequency;
private decreaseFrequency;
}

147
node_modules/sweet-collections/dist/map/LfuMap.js generated vendored Normal file
View File

@ -0,0 +1,147 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LfuMap = void 0;
const SizedMap_1 = require("./SizedMap");
class LfuMap extends SizedMap_1.SizedMap {
constructor() {
super(...arguments);
this.queue = {};
this.frequencies = { 1: { index: 1, count: 0 } };
this.leastFrequent = this.frequencies[1];
}
has(key) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
this.moveToTop(node);
return true;
}
return false;
}
get(key, _default) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
this.moveToTop(node);
return node.value;
}
return _default;
}
set(key, value) {
if (!this.limit)
return this;
let node = this.map.get(key);
if (node) {
node.value = value;
this.removeNode(node);
this.moveToTop(node);
}
else {
node = {
key: key,
value: value,
used: 0,
};
if (this.isFull()) {
super.delete(this.queuePop().key);
}
this.moveToTop(node);
this.map.set(key, node);
}
return this;
}
delete(key) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
return super.delete(key);
}
return false;
}
clear() {
this.queue = {};
this.frequencies = { 1: { index: 1, count: 0 } };
this.leastFrequent = this.frequencies[1];
super.clear();
}
initQueue(used) {
if (!this.queue[used]) {
this.queue[used] = {};
}
}
queuePop() {
const min = this.leastFrequent.index;
const node = this.queue[min].tail;
this.removeNode(node);
return node;
}
moveToTop(node) {
const used = ++node.used;
this.increaseFrequency(used);
this.initQueue(used);
node.next = this.queue[used].head;
node.previous = undefined;
if (this.queue[used].head) {
this.queue[used].head.previous = node;
}
this.queue[used].head = node;
if (!this.queue[used].tail) {
this.queue[used].tail = this.queue[used].head;
}
}
removeNode(node) {
const used = node.used;
this.decreaseFrequency(used);
this.initQueue(used);
if (node.previous) {
node.previous.next = node.next;
}
else {
this.queue[used].head = node.next;
}
if (node.next) {
node.next.previous = node.previous;
}
else {
this.queue[used].tail = node.previous;
}
}
increaseFrequency(index) {
if (!this.frequencies[index]) {
this.frequencies[index] = { index: index, count: 0 };
this.frequencies[index].next = this.frequencies[index - 1].next;
this.frequencies[index].previous = this.frequencies[index - 1].count
? this.frequencies[index - 1]
: this.frequencies[index - 1].previous;
}
if (!this.frequencies[index].count) {
if (this.frequencies[index].previous) {
this.frequencies[index].next = this.frequencies[index].previous.next;
this.frequencies[index].previous.next = this.frequencies[index];
}
if (this.frequencies[index].next) {
this.frequencies[index].previous = this.frequencies[index].next.previous;
this.frequencies[index].next.previous = this.frequencies[index];
}
}
this.frequencies[index].count++;
if (!this.leastFrequent || index < this.leastFrequent.index) {
this.leastFrequent = this.frequencies[index];
}
}
decreaseFrequency(index) {
this.frequencies[index].count--;
if (!this.frequencies[index].count) {
if (this.frequencies[index].previous) {
this.frequencies[index].previous.next = this.frequencies[index].next;
}
if (this.frequencies[index].next) {
this.frequencies[index].next.previous = this.frequencies[index].previous;
}
}
if (!this.leastFrequent || !this.leastFrequent.count) {
this.leastFrequent = this.leastFrequent.next;
}
}
}
exports.LfuMap = LfuMap;

12
node_modules/sweet-collections/dist/map/LruMap.d.ts generated vendored Normal file
View File

@ -0,0 +1,12 @@
import { SizedMap } from './SizedMap';
export declare class LruMap<K, V> extends SizedMap<K, V> {
private head?;
private tail?;
has(key: K): boolean;
get(key: K, _default?: V): V | undefined;
set(key: K, value: V): this;
delete(key: K): boolean;
clear(): void;
private moveToTop;
private removeNode;
}

82
node_modules/sweet-collections/dist/map/LruMap.js generated vendored Normal file
View File

@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LruMap = void 0;
const SizedMap_1 = require("./SizedMap");
class LruMap extends SizedMap_1.SizedMap {
has(key) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
this.moveToTop(node);
return true;
}
return false;
}
get(key, _default) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
this.moveToTop(node);
return node.value;
}
return _default;
}
set(key, value) {
let node = this.map.get(key);
if (node) {
node.value = value;
this.removeNode(node);
this.moveToTop(node);
}
else {
node = {
key: key,
value: value,
};
if (this.isFull()) {
this.delete(this.tail.key);
}
this.moveToTop(node);
this.map.set(key, node);
}
return this;
}
delete(key) {
const node = this.map.get(key);
if (node) {
this.removeNode(node);
return super.delete(key);
}
return false;
}
clear() {
this.head = this.tail = undefined;
super.clear();
}
moveToTop(node) {
node.next = this.head;
node.previous = undefined;
if (this.head) {
this.head.previous = node;
}
this.head = node;
if (!this.tail) {
this.tail = this.head;
}
}
removeNode(node) {
if (node.previous) {
node.previous.next = node.next;
}
else {
this.head = node.next;
}
if (node.next) {
node.next.previous = node.previous;
}
else {
this.tail = node.previous;
}
}
}
exports.LruMap = LruMap;

25
node_modules/sweet-collections/dist/map/SizedMap.d.ts generated vendored Normal file
View File

@ -0,0 +1,25 @@
export interface Node<K, V> {
key: K;
value: V;
used?: number;
previous?: Node<K, V>;
next?: Node<K, V>;
}
export declare abstract class SizedMap<K, V> implements Map<K, V> {
readonly limit: number;
protected readonly map: Map<K, Node<K, V>>;
constructor(limit: number);
abstract has(key: K): boolean;
abstract get(key: K, _default?: V): V | undefined;
abstract set(key: K, value: V): this;
delete(key: K): boolean;
keys(): IterableIterator<K>;
values(): IterableIterator<V>;
entries(): IterableIterator<[K, V]>;
isFull(): boolean;
clear(): void;
readonly [Symbol.toStringTag]: string;
[Symbol.iterator](): IterableIterator<[K, V]>;
forEach(cb: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
get size(): number;
}

41
node_modules/sweet-collections/dist/map/SizedMap.js generated vendored Normal file
View File

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SizedMap = void 0;
class SizedMap {
constructor(limit) {
if (limit < 0) {
throw new Error('Map size limit should positive.');
}
this.limit = limit;
this.map = new Map();
}
delete(key) {
return this.map.delete(key);
}
keys() {
return this.map.keys();
}
values() {
return [...this.map.values()].map((node) => node.value)[Symbol.iterator]();
}
entries() {
return [...this.map.values()]
.map((node) => [node.key, node.value])[Symbol.iterator]();
}
isFull() {
return this.size === this.limit;
}
clear() {
this.map.clear();
}
[Symbol.iterator]() {
return this.entries();
}
forEach(cb, thisArg) {
this.map.forEach((item) => cb.call(thisArg, item.value, item.key, this));
}
get size() {
return this.map.size;
}
}
exports.SizedMap = SizedMap;

17
node_modules/sweet-collections/dist/map/SortedMap.d.ts generated vendored Normal file
View File

@ -0,0 +1,17 @@
export declare class SortedMap<K, V> implements Map<K, V> {
private array;
private readonly comparator;
constructor(comparator: (a: K, b: K) => number);
has(key: K): boolean;
get(key: K, _default?: V): V | undefined;
set(key: K, value: V): this;
delete(key: K): boolean;
keys(): IterableIterator<K>;
values(): IterableIterator<V>;
entries(): IterableIterator<[K, V]>;
clear(): void;
readonly [Symbol.toStringTag]: string;
[Symbol.iterator](): IterableIterator<[K, V]>;
forEach(cb: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
get size(): number;
}

53
node_modules/sweet-collections/dist/map/SortedMap.js generated vendored Normal file
View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SortedMap = void 0;
const array_1 = require("../array");
class SortedMap {
constructor(comparator) {
this.comparator = comparator;
this.array = new array_1.SortedArray((a, b) => comparator(a.key, b.key), true);
}
has(key) {
return this.array.includes({ key: key, value: undefined });
}
get(key, _default) {
var _a, _b;
const index = this.array.firstIndexOf({ key: key, value: undefined });
return (_b = (_a = this.array.get(index)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : _default;
}
set(key, value) {
this.array.push({ key, value });
return this;
}
delete(key) {
return this.array.delete({ key: key, value: undefined });
}
keys() {
return this.array
.toArray()
.map((n) => n.key)[Symbol.iterator]();
}
values() {
return this.array
.toArray()
.map((n) => n.value)[Symbol.iterator]();
}
entries() {
return this.array
.toArray()
.map((n) => [n.key, n.value])[Symbol.iterator]();
}
clear() {
this.array.clear();
}
[Symbol.iterator]() {
return this.entries();
}
forEach(cb, thisArg) {
this.array.toArray().forEach((item) => cb.call(thisArg, item.value, item.key, this));
}
get size() {
return this.array.length;
}
}
exports.SortedMap = SortedMap;

3
node_modules/sweet-collections/dist/map/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from './LruMap';
export * from './LfuMap';
export * from './SortedMap';

15
node_modules/sweet-collections/dist/map/index.js generated vendored Normal file
View File

@ -0,0 +1,15 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./LruMap"), exports);
__exportStar(require("./LfuMap"), exports);
__exportStar(require("./SortedMap"), exports);