Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,4 +1,4 @@
[![Build Status](https://github.com/Yomguithereal/mnemonist/workflows/Tests/badge.svg)](https://github.com/Yomguithereal/mnemonist/actions)
[![Build Status](https://github.com/Yomguithereal/mnemonist/actions/workflows/tests.yml/badge.svg)](https://github.com/Yomguithereal/mnemonist/actions)
# Mnemonist

View File

@@ -8,6 +8,9 @@ export class InverseMap<K, V> implements Iterable<[K, V]> {
size: number;
inverse: BiMap<V, K>;
// Constructor
constructor(original: BiMap<K, V>);
// Methods
clear(): void;
set(key: K, value: V): this;
@@ -28,6 +31,9 @@ export default class BiMap<K, V> implements Iterable<[K, V]> {
size: number;
inverse: InverseMap<V, K>;
// Constructor
constructor();
// Methods
clear(): void;
set(key: K, value: V): this;

View File

@@ -25,5 +25,5 @@ export default class BloomFilter {
toJSON(): Uint8Array;
// Statics
from(iterable: Iterable<string>, options?: number | BloomFilterOptions): BloomFilter;
static from(iterable: Iterable<string>, options?: number | BloomFilterOptions): BloomFilter;
}

View File

@@ -45,15 +45,24 @@ if (typeof Symbol !== 'undefined')
* @return {number} - Returns the new size of the buffer.
*/
CircularBuffer.prototype.push = function(item) {
var index = (this.start + this.size) % this.capacity;
var index = this.start + this.size;
if (index >= this.capacity)
index -= this.capacity;
this.items[index] = item;
// Overwriting?
if (this.size === this.capacity) {
index++;
// If start is at the end, we wrap around the buffer
this.start = (index + 1) % this.capacity;
// Wrapping around?
if (index >= this.capacity) {
this.start = 0;
}
else {
this.start = index;
}
return this.size;
}

View File

@@ -317,4 +317,5 @@ MaxFibonacciHeap.from = function(iterable, comparator) {
*/
FibonacciHeap.MinFibonacciHeap = FibonacciHeap;
FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap;
module.exports = FibonacciHeap;

View File

@@ -48,7 +48,10 @@ FixedDeque.prototype.push = function(item) {
if (this.size === this.capacity)
throw new Error('mnemonist/fixed-deque.push: deque capacity (' + this.capacity + ') exceeded!');
var index = (this.start + this.size) % this.capacity;
var index = this.start + this.size;
if (index >= this.capacity)
index -= this.capacity;
this.items[index] = item;
@@ -85,10 +88,13 @@ FixedDeque.prototype.pop = function() {
if (this.size === 0)
return;
const index = (this.start + this.size - 1) % this.capacity;
this.size--;
var index = this.start + this.size;
if (index >= this.capacity)
index -= this.capacity;
return this.items[index];
};
@@ -135,7 +141,7 @@ FixedDeque.prototype.peekLast = function() {
var index = this.start + this.size - 1;
if (index > this.capacity)
if (index >= this.capacity)
index -= this.capacity;
return this.items[index];
@@ -148,12 +154,12 @@ FixedDeque.prototype.peekLast = function() {
* @return {any}
*/
FixedDeque.prototype.get = function(index) {
if (this.size === 0)
if (this.size === 0 || index >= this.capacity)
return;
index = this.start + index;
if (index > this.capacity)
if (index >= this.capacity)
index -= this.capacity;
return this.items[index];

View File

@@ -44,5 +44,5 @@ export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array';
export {default as SymSpell} from './symspell';
export {default as Trie} from './trie';
export {default as TrieMap} from './trie-map';
export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Array} from './vector';
export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector';
export {default as VPTree} from './vp-tree';

View File

@@ -1,13 +1,14 @@
/**
* Mnemonist Library Endpoint
* ===========================
* Mnemonist Library Endpoint (CommonJS)
* ======================================
*
* Exporting every data structure through a unified endpoint. Consumers
* of this library should prefer the modular access though.
*/
var Heap = require('./heap.js'),
FibonacciHeap = require('./fibonacci-heap.js'),
SuffixArray = require('./suffix-array.js');
SuffixArray = require('./suffix-array.js'),
Vector = require('./vector.js');
module.exports = {
BiMap: require('./bi-map.js'),
@@ -46,13 +47,23 @@ module.exports = {
Stack: require('./stack.js'),
SuffixArray: SuffixArray,
GeneralizedSuffixArray: SuffixArray.GeneralizedSuffixArray,
Set: require('./set.js'),
set: require('./set.js'),
SparseQueueSet: require('./sparse-queue-set.js'),
SparseMap: require('./sparse-map.js'),
SparseSet: require('./sparse-set.js'),
SymSpell: require('./symspell.js'),
Trie: require('./trie.js'),
TrieMap: require('./trie-map.js'),
Vector: require('./vector.js'),
Vector: Vector,
Uint8Vector: Vector.Uint8Vector,
Uint8ClampedVector: Vector.Uint8ClampedVector,
Int8Vector: Vector.Int8Vector,
Uint16Vector: Vector.Uint16Vector,
Int16Vector: Vector.Int16Vector,
Uint32Vector: Vector.Uint32Vector,
Int32Vector: Vector.Int32Vector,
Float32Vector: Vector.Float32Vector,
Float64Vector: Vector.Float64Vector,
PointerVector: Vector.PointerVector,
VPTree: require('./vp-tree.js')
};

67
backend/node_modules/mnemonist/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,67 @@
/**
* Mnemonist Library Endpoint (ESM)
* =================================
*
* Exporting every data structure through a unified endpoint.
*/
import * as set from './set.js';
import {default as FibonacciHeap} from './fibonacci-heap.js';
const MinFibonacciHeap = FibonacciHeap.MinFibonacciHeap;
const MaxFibonacciHeap = FibonacciHeap.MaxFibonacciHeap;
import {default as Heap} from './heap.js';
const MinHeap = Heap.MinHeap;
const MaxHeap = Heap.MaxHeap;
import {default as SuffixArray} from './suffix-array.js';
const GeneralizedSuffixArray = SuffixArray.GeneralizedSuffixArray;
import {default as Vector} from './vector.js';
const Uint8Vector = Vector.Uint8Vector;
const Uint8ClampedVector = Vector.Uint8ClampedVector;
const Int8Vector = Vector.Int8Vector;
const Uint16Vector = Vector.Uint16Vector;
const Int16Vector = Vector.Int16Vector;
const Uint32Vector = Vector.Uint32Vector;
const Int32Vector = Vector.Int32Vector;
const Float32Vector = Vector.Float32Vector;
const Float64Vector = Vector.Float64Vector;
const PointerVector = Vector.PointerVector;
export {default as BiMap} from './bi-map.js';
export {default as BitSet} from './bit-set.js';
export {default as BitVector} from './bit-vector.js';
export {default as BloomFilter} from './bloom-filter.js';
export {default as BKTree} from './bk-tree.js';
export {default as CircularBuffer} from './circular-buffer.js';
export {default as DefaultMap} from './default-map.js';
export {default as DefaultWeakMap} from './default-weak-map.js';
export {default as FixedDeque} from './fixed-deque.js';
export {default as StaticDisjointSet} from './static-disjoint-set.js';
export {FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap};
export {default as FixedReverseHeap} from './fixed-reverse-heap.js';
export {default as FuzzyMap} from './fuzzy-map.js';
export {default as FuzzyMultiMap} from './fuzzy-multi-map.js';
export {default as HashedArrayTree} from './hashed-array-tree.js';
export {Heap, MinHeap, MaxHeap};
export {default as StaticIntervalTree} from './static-interval-tree.js';
export {default as InvertedIndex} from './inverted-index.js';
export {default as KDTree} from './kd-tree.js';
export {default as LinkedList} from './linked-list.js';
export {default as LRUCache} from './lru-cache.js';
export {default as LRUCacheWithDelete} from './lru-cache-with-delete.js';
export {default as LRUMap} from './lru-map.js';
export {default as LRUMapWithDelete} from './lru-map-with-delete.js';
export {default as MultiMap} from './multi-map.js';
export {default as MultiSet} from './multi-set.js';
export {default as PassjoinIndex} from './passjoin-index.js';
export {default as Queue} from './queue.js';
export {default as FixedStack} from './fixed-stack.js';
export {default as Stack} from './stack.js';
export {SuffixArray, GeneralizedSuffixArray};
export {set};
export {default as SparseQueueSet} from './sparse-queue-set.js';
export {default as SparseMap} from './sparse-map.js';
export {default as SparseSet} from './sparse-set.js';
export {default as SymSpell} from './symspell.js';
export {default as Trie} from './trie.js';
export {default as TrieMap} from './trie-map.js';
export {Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector};
export {default as VPTree} from './vp-tree.js';

View File

@@ -11,6 +11,9 @@ export default class KDTree<V> {
size: number;
visited: number;
// Constructor
private constructor(dimensions: number, build: any);
// Methods
nearestNeighbor(point: Array<number>): V;
kNearestNeighbors(k: number, point: Array<number>): Array<V>;

View File

@@ -7,6 +7,9 @@ export default class LinkedList<T> implements Iterable<T> {
// Members
size: number;
// Constructor
constructor();
// Methods
clear(): void;
first(): T | undefined;
@@ -26,4 +29,4 @@ export default class LinkedList<T> implements Iterable<T> {
// Statics
static from<I>(iterable: Iterable<I> | {[key: string]: I}): LinkedList<I>;
}
}

View File

@@ -142,7 +142,7 @@ LRUCacheWithDelete.prototype.setpop = function(key, value) {
this.tail = this.backward[pointer];
oldValue = this.V[pointer];
oldKey = this.K[pointer];
delete this.items[this.K[pointer]];
delete this.items[oldKey];
}
// Storing key & value

View File

@@ -177,7 +177,7 @@ LRUCache.prototype.setpop = function(key, value) {
this.tail = this.backward[pointer];
oldValue = this.V[pointer];
oldKey = this.K[pointer];
delete this.items[this.K[pointer]];
delete this.items[oldKey];
}
// Storing key & value

View File

@@ -142,7 +142,7 @@ LRUMapWithDelete.prototype.setpop = function(key, value) {
this.tail = this.backward[pointer];
oldValue = this.V[pointer];
oldKey = this.K[pointer];
this.items.delete(this.K[pointer]);
this.items.delete(oldKey);
}
// Storing key & value

View File

@@ -137,7 +137,7 @@ LRUMap.prototype.setpop = function(key, value) {
this.tail = this.backward[pointer];
oldValue = this.V[pointer];
oldKey = this.K[pointer];
this.items.delete(this.K[pointer]);
this.items.delete(oldKey);
}
// Storing key & value

View File

@@ -44,4 +44,4 @@ interface MultiMapConstructor {
}
declare const MultiMap: MultiMapConstructor;
export default MultiMap;
export default MultiMap;

View File

@@ -8,6 +8,9 @@ export default class MultiSet<K> implements Iterable<K> {
dimension: number;
size: number;
// Constructor
constructor();
// Methods
clear(): void;
add(key: K, count?: number): this;

View File

@@ -1,21 +1,39 @@
{
"name": "mnemonist",
"version": "0.39.6",
"version": "0.40.3",
"description": "Curated collection of data structures for the JavaScript/TypeScript.",
"scripts": {
"lint": "eslint --cache ./*.js ./utils ./test",
"lint:fix": "eslint --cache --fix ./*.js ./utils ./test",
"prepublishOnly": "npm run lint && npm test && npm run test:types",
"lint": "eslint --cache --ext .js,.mjs ./*.js ./*.mjs ./utils ./test",
"lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test",
"prepublishOnly": "npm run lint && npm test && npm run test:exports",
"test": "mocha",
"test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts"
"test:exports": "cd test/exports && npm i && npm run test"
},
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./index.mjs"
},
"./*": {
"types": "./*.d.ts",
"require": "./*.js"
},
"./*.js": {
"types": "./*.d.ts",
"require": "./*.js"
}
},
"sideEffects": false,
"files": [
"sort",
"utils",
"*.d.ts",
"*.js"
"*.js",
"*.mjs"
],
"repository": {
"type": "git",
@@ -73,12 +91,12 @@
},
"homepage": "https://github.com/yomguithereal/mnemonist#readme",
"dependencies": {
"obliterator": "^2.0.1"
"obliterator": "^2.0.4"
},
"devDependencies": {
"@yomguithereal/eslint-config": "^4.4.0",
"asciitree": "^1.0.2",
"damerau-levenshtein": "^1.0.7",
"damerau-levenshtein": "^1.0.8",
"eslint": "^8.2.0",
"leven": "^3.1.0",
"lodash": "^4.17.21",
@@ -86,8 +104,7 @@
"mocha": "^9.1.3",
"pandemonium": "^2.0.0",
"seedrandom": "^3.0.5",
"static-kdtree": "^1.0.2",
"typescript": "^4.5.2"
"static-kdtree": "^1.0.2"
},
"eslintConfig": {
"extends": "@yomguithereal/eslint-config",
@@ -95,7 +112,8 @@
"ecmaVersion": 6,
"ecmaFeatures": {
"forOf": true
}
},
"sourceType": "module"
},
"rules": {
"no-new": 0

View File

@@ -7,6 +7,9 @@ export default class Queue<T> implements Iterable<T> {
// Members
size: number;
// Constructor
constructor();
// Methods
clear(): void;
enqueue(item: T): number;

View File

@@ -2,17 +2,17 @@
* Mnemonist Set Typings
* ======================
*/
export function intersection<T>(...set: Array<Set<T>>): Set<T>;
export function union<T>(...set: Array<Set<T>>): Set<T>;
export function difference<T>(a: Set<T>, b: Set<T>): Set<T>;
export function symmetricDifference<T>(a: Set<T>, b: Set<T>): Set<T>;
export function isSubset<T>(a: Set<T>, b: Set<T>): boolean;
export function isSuperset<T>(a: Set<T>, b: Set<T>): boolean;
export function add<T>(a: Set<T>, b: Set<T>): void;
export function subtract<T>(a: Set<T>, b: Set<T>): void;
export function intersect<T>(a: Set<T>, b: Set<T>): void;
export function disjunct<T>(a: Set<T>, b: Set<T>): void;
export function intersectionSize<T>(a: Set<T>, b: Set<T>): number;
export function unionSize<T>(a: Set<T>, b: Set<T>): number;
export function jaccard<T>(a: Set<T>, b: Set<T>): number;
export function overlap<T>(a: Set<T>, b: Set<T>): number;
export function intersection<T>(a: ReadonlySet<T>, b: ReadonlySet<T>, ...rest: Array<ReadonlySet<T>>): Set<T>;
export function union<T>(a: ReadonlySet<T>, b: ReadonlySet<T>, ...rest: Array<ReadonlySet<T>>): Set<T>;
export function difference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T>;
export function symmetricDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T>;
export function isSubset<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean;
export function isSuperset<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean;
export function add<T>(a: Set<T>, b: ReadonlySet<T>): void;
export function subtract<T>(a: Set<T>, b: ReadonlySet<T>): void;
export function intersect<T>(a: Set<T>, b: ReadonlySet<T>): void;
export function disjunct<T>(a: Set<T>, b: ReadonlySet<T>): void;
export function intersectionSize<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): number;
export function unionSize<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): number;
export function jaccard<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): number;
export function overlap<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): number;

View File

@@ -2,6 +2,8 @@
* Mnemonist SparseMap Typings
* ============================
*/
import {IArrayLikeConstructor} from './utils/types';
export default class SparseMap<V> implements Iterable<[number, V]> {
// Members
@@ -10,6 +12,7 @@ export default class SparseMap<V> implements Iterable<[number, V]> {
// Constructor
constructor(length: number);
constructor(values: IArrayLikeConstructor, length: number);
// Methods
clear(): void;

View File

@@ -7,6 +7,9 @@ export default class Stack<T> implements Iterable<T> {
// Members
size: number;
// Constructor
constructor();
// Methods
clear(): void;
push(item: T): number;

View File

@@ -349,4 +349,5 @@ if (typeof Symbol !== 'undefined')
* Exporting.
*/
SuffixArray.GeneralizedSuffixArray = GeneralizedSuffixArray;
module.exports = SuffixArray;

View File

@@ -78,4 +78,5 @@ export class Uint16Vector extends TypedVector {}
export class Int32Vector extends TypedVector {}
export class Uint32Vector extends TypedVector {}
export class Float32Vector extends TypedVector {}
export class Float64Array extends TypedVector {}
export class Float64Vector extends TypedVector {}
export class PointerVector extends TypedVector {}