linked-list-typed 2.1.0 → 2.1.2
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/dist/cjs/index.cjs +2152 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +2143 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/linked-list-typed.js +2146 -0
- package/dist/umd/linked-list-typed.js.map +1 -0
- package/dist/umd/linked-list-typed.min.js +9 -0
- package/dist/umd/linked-list-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { SkipLinkedListOptions } from '../../types';
|
|
2
|
-
export declare class SkipListNode<K, V> {
|
|
3
|
-
key: K;
|
|
4
|
-
value: V;
|
|
5
|
-
forward: SkipListNode<K, V>[];
|
|
6
|
-
constructor(key: K, value: V, level: number);
|
|
7
|
-
}
|
|
8
|
-
export declare class SkipList<K, V> {
|
|
9
|
-
constructor(elements?: Iterable<[K, V]>, options?: SkipLinkedListOptions);
|
|
10
|
-
protected _head: SkipListNode<K, V>;
|
|
11
|
-
get head(): SkipListNode<K, V>;
|
|
12
|
-
protected _level: number;
|
|
13
|
-
get level(): number;
|
|
14
|
-
protected _maxLevel: number;
|
|
15
|
-
get maxLevel(): number;
|
|
16
|
-
protected _probability: number;
|
|
17
|
-
get probability(): number;
|
|
18
|
-
get first(): V | undefined;
|
|
19
|
-
get last(): V | undefined;
|
|
20
|
-
add(key: K, value: V): void;
|
|
21
|
-
get(key: K): V | undefined;
|
|
22
|
-
has(key: K): boolean;
|
|
23
|
-
delete(key: K): boolean;
|
|
24
|
-
higher(key: K): V | undefined;
|
|
25
|
-
lower(key: K): V | undefined;
|
|
26
|
-
protected _randomLevel(): number;
|
|
27
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SkipList = exports.SkipListNode = void 0;
|
|
4
|
-
class SkipListNode {
|
|
5
|
-
constructor(key, value, level) {
|
|
6
|
-
this.key = key;
|
|
7
|
-
this.value = value;
|
|
8
|
-
this.forward = new Array(level);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.SkipListNode = SkipListNode;
|
|
12
|
-
class SkipList {
|
|
13
|
-
constructor(elements = [], options) {
|
|
14
|
-
this._head = new SkipListNode(undefined, undefined, this.maxLevel);
|
|
15
|
-
this._level = 0;
|
|
16
|
-
this._maxLevel = 16;
|
|
17
|
-
this._probability = 0.5;
|
|
18
|
-
if (options) {
|
|
19
|
-
const { maxLevel, probability } = options;
|
|
20
|
-
if (typeof maxLevel === 'number')
|
|
21
|
-
this._maxLevel = maxLevel;
|
|
22
|
-
if (typeof probability === 'number')
|
|
23
|
-
this._probability = probability;
|
|
24
|
-
}
|
|
25
|
-
if (elements) {
|
|
26
|
-
for (const [key, value] of elements)
|
|
27
|
-
this.add(key, value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
get head() {
|
|
31
|
-
return this._head;
|
|
32
|
-
}
|
|
33
|
-
get level() {
|
|
34
|
-
return this._level;
|
|
35
|
-
}
|
|
36
|
-
get maxLevel() {
|
|
37
|
-
return this._maxLevel;
|
|
38
|
-
}
|
|
39
|
-
get probability() {
|
|
40
|
-
return this._probability;
|
|
41
|
-
}
|
|
42
|
-
get first() {
|
|
43
|
-
const firstNode = this.head.forward[0];
|
|
44
|
-
return firstNode ? firstNode.value : undefined;
|
|
45
|
-
}
|
|
46
|
-
get last() {
|
|
47
|
-
let current = this.head;
|
|
48
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
49
|
-
while (current.forward[i]) {
|
|
50
|
-
current = current.forward[i];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return current.value;
|
|
54
|
-
}
|
|
55
|
-
add(key, value) {
|
|
56
|
-
const newNode = new SkipListNode(key, value, this._randomLevel());
|
|
57
|
-
const update = new Array(this.maxLevel).fill(this.head);
|
|
58
|
-
let current = this.head;
|
|
59
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
60
|
-
while (current.forward[i] && current.forward[i].key < key) {
|
|
61
|
-
current = current.forward[i];
|
|
62
|
-
}
|
|
63
|
-
update[i] = current;
|
|
64
|
-
}
|
|
65
|
-
for (let i = 0; i < newNode.forward.length; i++) {
|
|
66
|
-
newNode.forward[i] = update[i].forward[i];
|
|
67
|
-
update[i].forward[i] = newNode;
|
|
68
|
-
}
|
|
69
|
-
if (!newNode.forward[0]) {
|
|
70
|
-
this._level = Math.max(this.level, newNode.forward.length);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
get(key) {
|
|
74
|
-
let current = this.head;
|
|
75
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
76
|
-
while (current.forward[i] && current.forward[i].key < key) {
|
|
77
|
-
current = current.forward[i];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
current = current.forward[0];
|
|
81
|
-
if (current && current.key === key) {
|
|
82
|
-
return current.value;
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
has(key) {
|
|
87
|
-
return this.get(key) !== undefined;
|
|
88
|
-
}
|
|
89
|
-
delete(key) {
|
|
90
|
-
const update = new Array(this.maxLevel).fill(this.head);
|
|
91
|
-
let current = this.head;
|
|
92
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
93
|
-
while (current.forward[i] && current.forward[i].key < key) {
|
|
94
|
-
current = current.forward[i];
|
|
95
|
-
}
|
|
96
|
-
update[i] = current;
|
|
97
|
-
}
|
|
98
|
-
current = current.forward[0];
|
|
99
|
-
if (current && current.key === key) {
|
|
100
|
-
for (let i = 0; i < this.level; i++) {
|
|
101
|
-
if (update[i].forward[i] !== current) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
update[i].forward[i] = current.forward[i];
|
|
105
|
-
}
|
|
106
|
-
while (this.level > 0 && !this.head.forward[this.level - 1]) {
|
|
107
|
-
this._level--;
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
higher(key) {
|
|
114
|
-
let current = this.head;
|
|
115
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
116
|
-
while (current.forward[i] && current.forward[i].key <= key) {
|
|
117
|
-
current = current.forward[i];
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const nextNode = current.forward[0];
|
|
121
|
-
return nextNode ? nextNode.value : undefined;
|
|
122
|
-
}
|
|
123
|
-
lower(key) {
|
|
124
|
-
let current = this.head;
|
|
125
|
-
let lastLess = undefined;
|
|
126
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
127
|
-
while (current.forward[i] && current.forward[i].key < key) {
|
|
128
|
-
current = current.forward[i];
|
|
129
|
-
}
|
|
130
|
-
if (current.key < key) {
|
|
131
|
-
lastLess = current;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return lastLess ? lastLess.value : undefined;
|
|
135
|
-
}
|
|
136
|
-
_randomLevel() {
|
|
137
|
-
let level = 1;
|
|
138
|
-
while (Math.random() < this.probability && level < this.maxLevel) {
|
|
139
|
-
level++;
|
|
140
|
-
}
|
|
141
|
-
return level;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.SkipList = SkipList;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./matrix"), exports);
|
|
18
|
-
__exportStar(require("./navigator"), exports);
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { MatrixOptions } from '../../types';
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export declare class Matrix {
|
|
13
|
-
/**
|
|
14
|
-
* The constructor function initializes a matrix object with the provided data and options, or with
|
|
15
|
-
* default values if no options are provided.
|
|
16
|
-
* @param {number[][]} data - A 2D array of numbers representing the data for the matrix.
|
|
17
|
-
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
18
|
-
* properties:
|
|
19
|
-
*/
|
|
20
|
-
constructor(data: number[][], options?: MatrixOptions);
|
|
21
|
-
protected _rows: number;
|
|
22
|
-
/**
|
|
23
|
-
* The function returns the number of rows.
|
|
24
|
-
* @returns The number of rows.
|
|
25
|
-
*/
|
|
26
|
-
get rows(): number;
|
|
27
|
-
protected _cols: number;
|
|
28
|
-
/**
|
|
29
|
-
* The function returns the value of the protected variable _cols.
|
|
30
|
-
* @returns The number of columns.
|
|
31
|
-
*/
|
|
32
|
-
get cols(): number;
|
|
33
|
-
protected _data: number[][];
|
|
34
|
-
/**
|
|
35
|
-
* The function returns a two-dimensional array of numbers.
|
|
36
|
-
* @returns The data property, which is a two-dimensional array of numbers.
|
|
37
|
-
*/
|
|
38
|
-
get data(): number[][];
|
|
39
|
-
/**
|
|
40
|
-
* The above function returns the value of the _addFn property.
|
|
41
|
-
* @returns The value of the property `_addFn` is being returned.
|
|
42
|
-
*/
|
|
43
|
-
get addFn(): (a: number | undefined, b: number) => number | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* The function returns the value of the _subtractFn property.
|
|
46
|
-
* @returns The `_subtractFn` property is being returned.
|
|
47
|
-
*/
|
|
48
|
-
get subtractFn(): (a: number, b: number) => number;
|
|
49
|
-
/**
|
|
50
|
-
* The function returns the value of the _multiplyFn property.
|
|
51
|
-
* @returns The `_multiplyFn` property is being returned.
|
|
52
|
-
*/
|
|
53
|
-
get multiplyFn(): (a: number, b: number) => number;
|
|
54
|
-
/**
|
|
55
|
-
* The `get` function returns the value at the specified row and column index if it is a valid index.
|
|
56
|
-
* @param {number} row - The `row` parameter represents the row index of the element you want to
|
|
57
|
-
* retrieve from the data array.
|
|
58
|
-
* @param {number} col - The parameter "col" represents the column number of the element you want to
|
|
59
|
-
* retrieve from the data array.
|
|
60
|
-
* @returns The `get` function returns a number if the provided row and column indices are valid.
|
|
61
|
-
* Otherwise, it returns `undefined`.
|
|
62
|
-
*/
|
|
63
|
-
get(row: number, col: number): number | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* The set function updates the value at a specified row and column in a two-dimensional array.
|
|
66
|
-
* @param {number} row - The "row" parameter represents the row index of the element in a
|
|
67
|
-
* two-dimensional array or matrix. It specifies the row where the value will be set.
|
|
68
|
-
* @param {number} col - The "col" parameter represents the column index of the element in a
|
|
69
|
-
* two-dimensional array.
|
|
70
|
-
* @param {number} value - The value parameter represents the number that you want to set at the
|
|
71
|
-
* specified row and column in the data array.
|
|
72
|
-
* @returns a boolean value. It returns true if the index (row, col) is valid and the value is
|
|
73
|
-
* successfully set in the data array. It returns false if the index is invalid and the value is not
|
|
74
|
-
* set.
|
|
75
|
-
*/
|
|
76
|
-
set(row: number, col: number, value: number): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* The function checks if the dimensions of the given matrix match the dimensions of the current
|
|
79
|
-
* matrix.
|
|
80
|
-
* @param {Matrix} matrix - The parameter `matrix` is of type `Matrix`.
|
|
81
|
-
* @returns a boolean value.
|
|
82
|
-
*/
|
|
83
|
-
isMatchForCalculate(matrix: Matrix): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* The `add` function adds two matrices together, returning a new matrix with the result.
|
|
86
|
-
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
87
|
-
* @returns The `add` method returns a new `Matrix` object that represents the result of adding the
|
|
88
|
-
* current matrix with the provided `matrix` parameter.
|
|
89
|
-
*/
|
|
90
|
-
add(matrix: Matrix): Matrix | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* The `subtract` function performs element-wise subtraction between two matrices and returns a new
|
|
93
|
-
* matrix with the result.
|
|
94
|
-
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class. It
|
|
95
|
-
* represents the matrix that you want to subtract from the current matrix.
|
|
96
|
-
* @returns a new Matrix object with the result of the subtraction operation.
|
|
97
|
-
*/
|
|
98
|
-
subtract(matrix: Matrix): Matrix | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* The `multiply` function performs matrix multiplication between two matrices and returns the result
|
|
101
|
-
* as a new matrix.
|
|
102
|
-
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
103
|
-
* @returns a new Matrix object.
|
|
104
|
-
*/
|
|
105
|
-
multiply(matrix: Matrix): Matrix | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* The transpose function takes a matrix and returns a new matrix that is the transpose of the
|
|
108
|
-
* original matrix.
|
|
109
|
-
* @returns The transpose() function returns a new Matrix object with the transposed data.
|
|
110
|
-
*/
|
|
111
|
-
transpose(): Matrix;
|
|
112
|
-
/**
|
|
113
|
-
* The `inverse` function calculates the inverse of a square matrix using Gaussian elimination.
|
|
114
|
-
* @returns a Matrix object, which represents the inverse of the original matrix.
|
|
115
|
-
*/
|
|
116
|
-
inverse(): Matrix | undefined;
|
|
117
|
-
/**
|
|
118
|
-
* The dot function calculates the dot product of two matrices and returns a new matrix.
|
|
119
|
-
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
120
|
-
* @returns a new Matrix object.
|
|
121
|
-
*/
|
|
122
|
-
dot(matrix: Matrix): Matrix | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* The function checks if a given row and column index is valid within a specified range.
|
|
125
|
-
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
|
|
126
|
-
* matrix. It is a number that indicates the specific row in the matrix.
|
|
127
|
-
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
|
|
128
|
-
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
|
|
129
|
-
* @returns A boolean value is being returned.
|
|
130
|
-
*/
|
|
131
|
-
isValidIndex(row: number, col: number): boolean;
|
|
132
|
-
/**
|
|
133
|
-
* The `clone` function returns a new instance of the Matrix class with the same data and properties
|
|
134
|
-
* as the original instance.
|
|
135
|
-
* @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
|
|
136
|
-
* and properties as the current instance.
|
|
137
|
-
*/
|
|
138
|
-
clone(): Matrix;
|
|
139
|
-
protected _addFn(a: number | undefined, b: number): number | undefined;
|
|
140
|
-
protected _subtractFn(a: number, b: number): number;
|
|
141
|
-
protected _multiplyFn(a: number, b: number): number;
|
|
142
|
-
/**
|
|
143
|
-
* The function `_swapRows` swaps the positions of two rows in an array.
|
|
144
|
-
* @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.
|
|
145
|
-
* @param {number} row2 - The `row2` parameter is the index of the second row that you want to swap
|
|
146
|
-
* with the first row.
|
|
147
|
-
*/
|
|
148
|
-
protected _swapRows(row1: number, row2: number): void;
|
|
149
|
-
/**
|
|
150
|
-
* The function scales a specific row in a matrix by a given scalar value.
|
|
151
|
-
* @param {number} row - The `row` parameter represents the index of the row in the matrix that you
|
|
152
|
-
* want to scale. It is a number that indicates the position of the row within the matrix.
|
|
153
|
-
* @param {number} scalar - The scalar parameter is a number that is used to multiply each element in
|
|
154
|
-
* a specific row of a matrix.
|
|
155
|
-
*/
|
|
156
|
-
protected _scaleRow(row: number, scalar: number): void;
|
|
157
|
-
/**
|
|
158
|
-
* The function `_addScaledRow` multiplies a row in a matrix by a scalar value and adds it to another
|
|
159
|
-
* row.
|
|
160
|
-
* @param {number} targetRow - The targetRow parameter represents the index of the row in which the
|
|
161
|
-
* scaled values will be added.
|
|
162
|
-
* @param {number} sourceRow - The sourceRow parameter represents the index of the row from which the
|
|
163
|
-
* values will be scaled and added to the targetRow.
|
|
164
|
-
* @param {number} scalar - The scalar parameter is a number that is used to scale the values in the
|
|
165
|
-
* source row before adding them to the target row.
|
|
166
|
-
*/
|
|
167
|
-
protected _addScaledRow(targetRow: number, sourceRow: number, scalar: number): void;
|
|
168
|
-
}
|