data-structure-typed 1.35.0 → 1.40.0-rc
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/.github/workflows/ci.yml +3 -0
- package/CHANGELOG.md +3 -1
- package/CONTRIBUTING.md +18 -0
- package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +21 -0
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +269 -4
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +83 -0
- package/dist/data-structures/heap/heap.js +62 -0
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +23 -0
- package/dist/data-structures/heap/max-heap.js +16 -0
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +24 -0
- package/dist/data-structures/heap/min-heap.js +17 -0
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
- package/dist/data-structures/priority-queue/priority-queue.js +141 -0
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/package.json +11 -7
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +8 -8
- package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/graph/index.ts +0 -2
- package/test/unit/data-structures/linked-list/index.ts +0 -4
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Heap = exports.HeapItem = void 0;
|
|
4
4
|
class HeapItem {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor function initializes an instance of a class with a priority and a value.
|
|
7
|
+
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
8
|
+
* optional and has a default value of `NaN`.
|
|
9
|
+
* @param {V | null} [val=null] - The `val` parameter is of type `V | null`, which means it can accept a value of type
|
|
10
|
+
* `V` or `null`.
|
|
11
|
+
*/
|
|
5
12
|
constructor(priority = Number.MAX_SAFE_INTEGER, val = null) {
|
|
6
13
|
this._val = val;
|
|
7
14
|
this._priority = priority;
|
|
@@ -21,6 +28,11 @@ class HeapItem {
|
|
|
21
28
|
}
|
|
22
29
|
exports.HeapItem = HeapItem;
|
|
23
30
|
class Heap {
|
|
31
|
+
/**
|
|
32
|
+
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
33
|
+
* options provided.
|
|
34
|
+
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
35
|
+
*/
|
|
24
36
|
constructor(options) {
|
|
25
37
|
if (options) {
|
|
26
38
|
const { priorityExtractor } = options;
|
|
@@ -39,27 +51,57 @@ class Heap {
|
|
|
39
51
|
get priorityExtractor() {
|
|
40
52
|
return this._priorityExtractor;
|
|
41
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The function returns the size of a priority queue.
|
|
56
|
+
* @returns The size of the priority queue.
|
|
57
|
+
*/
|
|
42
58
|
get size() {
|
|
43
59
|
return this._pq.size;
|
|
44
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The function checks if a priority queue is empty.
|
|
63
|
+
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
64
|
+
*/
|
|
45
65
|
isEmpty() {
|
|
46
66
|
return this._pq.size < 1;
|
|
47
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The `peek` function returns the top item in the priority queue without removing it.
|
|
70
|
+
* @returns The `peek()` method is returning either a `HeapItem<V>` object or `null`.Returns an val with the highest priority in the queue
|
|
71
|
+
*/
|
|
48
72
|
peek(isItem) {
|
|
49
73
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
50
74
|
const peeked = this._pq.peek();
|
|
51
75
|
return isItem ? peeked : peeked === null || peeked === void 0 ? void 0 : peeked.val;
|
|
52
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The `peekLast` function returns the last item in the heap.
|
|
79
|
+
* @returns The method `peekLast()` returns either a `HeapItem<V>` object or `null`.Returns an val with the lowest priority in the queue
|
|
80
|
+
*/
|
|
53
81
|
peekLast(isItem) {
|
|
54
82
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
55
83
|
const leafItem = this._pq.leaf();
|
|
56
84
|
return isItem ? leafItem : leafItem === null || leafItem === void 0 ? void 0 : leafItem.val;
|
|
57
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The `add` function adds an val to a priority queue with an optional priority value.
|
|
88
|
+
* @param {V} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
|
|
89
|
+
* type.
|
|
90
|
+
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
91
|
+
* val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
|
|
92
|
+
* the value of `val`. If the `val` parameter is not a number, then the
|
|
93
|
+
* @returns The `add` method returns the instance of the `Heap` class.
|
|
94
|
+
* @throws {Error} if priority is not a valid number
|
|
95
|
+
*/
|
|
58
96
|
add(priority, val) {
|
|
59
97
|
val = val === undefined ? priority : val;
|
|
60
98
|
this._pq.add(new HeapItem(priority, val));
|
|
61
99
|
return this;
|
|
62
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
|
|
103
|
+
* @returns either a HeapItem<V> object or null.
|
|
104
|
+
*/
|
|
63
105
|
poll(isItem) {
|
|
64
106
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
65
107
|
const top = this._pq.poll();
|
|
@@ -68,6 +110,11 @@ class Heap {
|
|
|
68
110
|
}
|
|
69
111
|
return isItem ? top : top.val;
|
|
70
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* The function checks if a given node or value exists in the priority queue.
|
|
115
|
+
* @param {V | HeapItem<V>} node - The parameter `node` can be of type `V` or `HeapItem<V>`.
|
|
116
|
+
* @returns a boolean value.
|
|
117
|
+
*/
|
|
71
118
|
has(node) {
|
|
72
119
|
if (node instanceof HeapItem) {
|
|
73
120
|
return this.pq.getNodes().includes(node);
|
|
@@ -78,16 +125,31 @@ class Heap {
|
|
|
78
125
|
}) !== -1);
|
|
79
126
|
}
|
|
80
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* The `toArray` function returns an array of `HeapItem<V>` objects.
|
|
130
|
+
* @returns An array of HeapItem<V> objects.Returns a sorted list of vals
|
|
131
|
+
*/
|
|
81
132
|
toArray(isItem) {
|
|
82
133
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
83
134
|
const itemArray = this._pq.toArray();
|
|
84
135
|
return isItem ? itemArray : itemArray.map(item => item.val);
|
|
85
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* The function sorts the elements in the priority queue and returns either the sorted items or their values depending
|
|
139
|
+
* on the value of the isItem parameter.
|
|
140
|
+
* @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
|
|
141
|
+
* be an array of `HeapItem<V>` objects or an array of the values (`V`) of those objects. If `isItem` is `true`, the
|
|
142
|
+
* sorted result will be an array of `HeapItem
|
|
143
|
+
* @returns an array of either `HeapItem<V>`, `null`, `V`, or `undefined` values.
|
|
144
|
+
*/
|
|
86
145
|
sort(isItem) {
|
|
87
146
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
88
147
|
const sorted = this._pq.sort();
|
|
89
148
|
return isItem ? sorted : sorted.map(item => item.val);
|
|
90
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The clear function clears the priority queue.
|
|
152
|
+
*/
|
|
91
153
|
clear() {
|
|
92
154
|
this._pq.clear();
|
|
93
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/heap.ts"],"names":[],"mappings":";;;AAUA,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/heap.ts"],"names":[],"mappings":";;;AAUA,MAAa,QAAQ;IACnB;;;;;;OAMG;IACH,YAAY,WAAmB,MAAM,CAAC,gBAAgB,EAAE,MAAgB,IAAI;QAC1E,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,KAAa;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,CAAC,KAAe;QACrB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;CACF;AAhCD,4BAgCC;AAED,MAAsB,IAAI;IACxB;;;;OAIG;IACH,YAAsB,OAAwB;QAC5C,IAAI,OAAO,EAAE;YACX,MAAM,EAAC,iBAAiB,EAAC,GAAG,OAAO,CAAC;YACpC,IAAI,iBAAiB,KAAK,SAAS,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE;gBAC9E,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;aACnE;YACD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;SAC5D;aAAM;YACL,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;SACrC;IACH,CAAC;IAID,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAGD,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;IAC3B,CAAC;IAMD;;;OAGG;IACH,IAAI,CAAC,MAAgB;QACnB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE/B,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC;IACvC,CAAC;IAMD;;;OAGG;IACH,QAAQ,CAAC,MAAgB;QACvB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAEjC,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,CAAC;IAC3C,CAAC;IAED;;;;;;;;;OASG;IACH,GAAG,CAAC,QAAgB,EAAE,GAAO;QAC3B,GAAG,GAAG,GAAG,KAAK,SAAS,CAAC,CAAC,CAAE,QAAyB,CAAC,CAAC,CAAC,GAAG,CAAC;QAC3D,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAI,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC;IACd,CAAC;IAMD;;;OAGG;IACH,IAAI,CAAC,MAAgB;QACnB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAqB;QACvB,IAAI,IAAI,YAAY,QAAQ,EAAE;YAC5B,OAAO,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;SAC1C;aAAM;YACL,OAAO,CACL,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBAClC,OAAO,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC;YAC3B,CAAC,CAAC,KAAK,CAAC,CAAC,CACV,CAAC;SACH;IACH,CAAC;IAMD;;;OAGG;IACH,OAAO,CAAC,MAAgB;QACtB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QAErC,OAAO,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9D,CAAC;IAMD;;;;;;;OAOG;IACH,IAAI,CAAC,MAAgB;QACnB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAE/B,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;CACF;AAvKD,oBAuKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import { Heap, HeapItem } from './heap';
|
|
9
|
+
import { PriorityQueue } from '../priority-queue';
|
|
10
|
+
import type { HeapOptions } from '../../types';
|
|
11
|
+
/**
|
|
12
|
+
* @class MaxHeap
|
|
13
|
+
* @extends Heap
|
|
14
|
+
*/
|
|
15
|
+
export declare class MaxHeap<V = any> extends Heap<V> {
|
|
16
|
+
protected _pq: PriorityQueue<HeapItem<V>>;
|
|
17
|
+
/**
|
|
18
|
+
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
19
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
20
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options?: HeapOptions<V>);
|
|
23
|
+
}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.MaxHeap = void 0;
|
|
4
11
|
const heap_1 = require("./heap");
|
|
5
12
|
const priority_queue_1 = require("../priority-queue");
|
|
13
|
+
/**
|
|
14
|
+
* @class MaxHeap
|
|
15
|
+
* @extends Heap
|
|
16
|
+
*/
|
|
6
17
|
class MaxHeap extends heap_1.Heap {
|
|
18
|
+
/**
|
|
19
|
+
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
20
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
21
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
22
|
+
*/
|
|
7
23
|
constructor(options) {
|
|
8
24
|
super(options);
|
|
9
25
|
this._pq = new priority_queue_1.PriorityQueue({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/max-heap.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"max-heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/max-heap.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAAsC;AACtC,sDAAgD;AAGhD;;;GAGG;AACH,MAAa,OAAiB,SAAQ,WAAO;IAG3C;;;;OAIG;IACH,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,IAAI,8BAAa,CAAc;YACxC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ;SAC9C,CAAC,CAAC;IACL,CAAC;CACF;AAdD,0BAcC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import { Heap, HeapItem } from './heap';
|
|
9
|
+
import { PriorityQueue } from '../priority-queue';
|
|
10
|
+
import type { HeapOptions } from '../../types';
|
|
11
|
+
/**
|
|
12
|
+
* @class MinHeap
|
|
13
|
+
* @extends Heap
|
|
14
|
+
*/
|
|
15
|
+
export declare class MinHeap<V = any> extends Heap<V> {
|
|
16
|
+
protected _pq: PriorityQueue<HeapItem<V>>;
|
|
17
|
+
/**
|
|
18
|
+
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
19
|
+
* objects.
|
|
20
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
21
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: HeapOptions<V>);
|
|
24
|
+
}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.MinHeap = void 0;
|
|
4
11
|
const heap_1 = require("./heap");
|
|
5
12
|
const priority_queue_1 = require("../priority-queue");
|
|
13
|
+
/**
|
|
14
|
+
* @class MinHeap
|
|
15
|
+
* @extends Heap
|
|
16
|
+
*/
|
|
6
17
|
class MinHeap extends heap_1.Heap {
|
|
18
|
+
/**
|
|
19
|
+
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
20
|
+
* objects.
|
|
21
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
22
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
23
|
+
*/
|
|
7
24
|
constructor(options) {
|
|
8
25
|
super(options);
|
|
9
26
|
this._pq = new priority_queue_1.PriorityQueue({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/min-heap.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"min-heap.js","sourceRoot":"","sources":["../../../src/data-structures/heap/min-heap.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAAsC;AACtC,sDAAgD;AAGhD;;;GAGG;AACH,MAAa,OAAiB,SAAQ,WAAO;IAG3C;;;;;OAKG;IACH,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,IAAI,8BAAa,CAAc;YACxC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ;SAC9C,CAAC,CAAC;IACL,CAAC;CACF;AAfD,0BAeC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './hash';
|
|
2
|
+
export * from './linked-list';
|
|
3
|
+
export * from './stack';
|
|
4
|
+
export * from './queue';
|
|
5
|
+
export * from './graph';
|
|
6
|
+
export * from './binary-tree';
|
|
7
|
+
export * from './tree';
|
|
8
|
+
export * from './heap';
|
|
9
|
+
export * from './priority-queue';
|
|
10
|
+
export * from './matrix';
|
|
11
|
+
export * from './trie';
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export declare class DoublyLinkedListNode<E = any> {
|
|
9
|
+
/**
|
|
10
|
+
* The constructor function initializes the value, next, and previous properties of an object.
|
|
11
|
+
* @param {E} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
12
|
+
* is defined as a generic type "E".
|
|
13
|
+
*/
|
|
14
|
+
constructor(val: E);
|
|
15
|
+
private _val;
|
|
16
|
+
get val(): E;
|
|
17
|
+
set val(value: E);
|
|
18
|
+
private _next;
|
|
19
|
+
get next(): DoublyLinkedListNode<E> | null;
|
|
20
|
+
set next(value: DoublyLinkedListNode<E> | null);
|
|
21
|
+
private _prev;
|
|
22
|
+
get prev(): DoublyLinkedListNode<E> | null;
|
|
23
|
+
set prev(value: DoublyLinkedListNode<E> | null);
|
|
24
|
+
}
|
|
25
|
+
export declare class DoublyLinkedList<E = any> {
|
|
26
|
+
/**
|
|
27
|
+
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
28
|
+
*/
|
|
29
|
+
constructor();
|
|
30
|
+
private _head;
|
|
31
|
+
get head(): DoublyLinkedListNode<E> | null;
|
|
32
|
+
set head(value: DoublyLinkedListNode<E> | null);
|
|
33
|
+
private _tail;
|
|
34
|
+
get tail(): DoublyLinkedListNode<E> | null;
|
|
35
|
+
set tail(value: DoublyLinkedListNode<E> | null);
|
|
36
|
+
private _length;
|
|
37
|
+
get length(): number;
|
|
38
|
+
/**
|
|
39
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
40
|
+
* given array.
|
|
41
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
42
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
43
|
+
*/
|
|
44
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E>;
|
|
45
|
+
/**
|
|
46
|
+
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
47
|
+
* @param {E} val - The value to be added to the linked list.
|
|
48
|
+
*/
|
|
49
|
+
push(val: E): void;
|
|
50
|
+
/**
|
|
51
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
52
|
+
* @param {E} val - The value to be added to the linked list.
|
|
53
|
+
*/
|
|
54
|
+
addLast(val: E): void;
|
|
55
|
+
/**
|
|
56
|
+
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
57
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
58
|
+
* list is empty, it returns null.
|
|
59
|
+
*/
|
|
60
|
+
pop(): E | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
63
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
64
|
+
* list is empty, it returns null.
|
|
65
|
+
*/
|
|
66
|
+
pollLast(): E | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
69
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
70
|
+
* list.
|
|
71
|
+
*/
|
|
72
|
+
shift(): E | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
75
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
76
|
+
* list.
|
|
77
|
+
*/
|
|
78
|
+
pollFirst(): E | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
81
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
82
|
+
* doubly linked list.
|
|
83
|
+
*/
|
|
84
|
+
unshift(val: E): void;
|
|
85
|
+
/**
|
|
86
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
87
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
88
|
+
* doubly linked list.
|
|
89
|
+
*/
|
|
90
|
+
addFirst(val: E): void;
|
|
91
|
+
/**
|
|
92
|
+
* The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
93
|
+
* @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
94
|
+
*/
|
|
95
|
+
peekFirst(): E | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
98
|
+
* @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
99
|
+
*/
|
|
100
|
+
peekLast(): E | undefined;
|
|
101
|
+
get size(): number;
|
|
102
|
+
/**
|
|
103
|
+
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
104
|
+
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
105
|
+
* retrieve from the list.
|
|
106
|
+
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
107
|
+
* or the linked list is empty, it will return null.
|
|
108
|
+
*/
|
|
109
|
+
getAt(index: number): E | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
112
|
+
* range.
|
|
113
|
+
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
114
|
+
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
115
|
+
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
116
|
+
* valid range of the linked list, otherwise it returns `null`.
|
|
117
|
+
*/
|
|
118
|
+
getNodeAt(index: number): DoublyLinkedListNode<E> | null;
|
|
119
|
+
/**
|
|
120
|
+
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
121
|
+
* node if found, otherwise it returns null.
|
|
122
|
+
* @param {E} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
123
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
|
|
124
|
+
* is found in the linked list. If no such node is found, it returns `null`.
|
|
125
|
+
*/
|
|
126
|
+
findNode(val: E): DoublyLinkedListNode<E> | null;
|
|
127
|
+
/**
|
|
128
|
+
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
129
|
+
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
130
|
+
* DoublyLinkedList. It is of type number.
|
|
131
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
132
|
+
* specified index.
|
|
133
|
+
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
134
|
+
* if the index is out of bounds.
|
|
135
|
+
*/
|
|
136
|
+
insertAt(index: number, val: E): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
139
|
+
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
140
|
+
* data structure. It is of type number.
|
|
141
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
142
|
+
* bounds.
|
|
143
|
+
*/
|
|
144
|
+
deleteAt(index: number): E | undefined;
|
|
145
|
+
delete(valOrNode: E): boolean;
|
|
146
|
+
delete(valOrNode: DoublyLinkedListNode<E>): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* The `toArray` function converts a linked list into an array.
|
|
149
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
150
|
+
*/
|
|
151
|
+
toArray(): E[];
|
|
152
|
+
/**
|
|
153
|
+
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
154
|
+
* @returns A boolean value is being returned.
|
|
155
|
+
*/
|
|
156
|
+
isEmpty(): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
159
|
+
*/
|
|
160
|
+
clear(): void;
|
|
161
|
+
/**
|
|
162
|
+
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
163
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
164
|
+
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
165
|
+
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
166
|
+
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
167
|
+
*/
|
|
168
|
+
find(callback: (val: E) => boolean): E | null;
|
|
169
|
+
/**
|
|
170
|
+
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
171
|
+
* @param {E} val - The parameter `val` is of type `E`, which means it can be any data type. It represents the value
|
|
172
|
+
* that we are searching for in the linked list.
|
|
173
|
+
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
174
|
+
* list. If the value is not found, it returns -1.
|
|
175
|
+
*/
|
|
176
|
+
indexOf(val: E): number;
|
|
177
|
+
/**
|
|
178
|
+
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
|
|
179
|
+
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
180
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
181
|
+
* function is used to determine whether a given value satisfies a certain condition.
|
|
182
|
+
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
183
|
+
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
184
|
+
*/
|
|
185
|
+
findLast(callback: (val: E) => boolean): E | null;
|
|
186
|
+
/**
|
|
187
|
+
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
|
|
188
|
+
* @returns The `toArrayReverse()` function returns an array of type `E[]`.
|
|
189
|
+
*/
|
|
190
|
+
toArrayReverse(): E[];
|
|
191
|
+
/**
|
|
192
|
+
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
193
|
+
*/
|
|
194
|
+
reverse(): void;
|
|
195
|
+
/**
|
|
196
|
+
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
197
|
+
* @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
|
|
198
|
+
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
199
|
+
* current node in the linked list.
|
|
200
|
+
*/
|
|
201
|
+
forEach(callback: (val: E, index: number) => void): void;
|
|
202
|
+
/**
|
|
203
|
+
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
204
|
+
* DoublyLinkedList with the transformed values.
|
|
205
|
+
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
206
|
+
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
207
|
+
* DoublyLinkedList).
|
|
208
|
+
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
209
|
+
*/
|
|
210
|
+
map<U>(callback: (val: E) => U): DoublyLinkedList<U>;
|
|
211
|
+
/**
|
|
212
|
+
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
213
|
+
* elements that satisfy the given callback function.
|
|
214
|
+
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
215
|
+
* It is used to determine whether a value should be included in the filtered list or not.
|
|
216
|
+
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
217
|
+
*/
|
|
218
|
+
filter(callback: (val: E) => boolean): DoublyLinkedList<E>;
|
|
219
|
+
/**
|
|
220
|
+
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
221
|
+
* single value.
|
|
222
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
|
|
223
|
+
* used to perform a specific operation on each element of the linked list.
|
|
224
|
+
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
225
|
+
* point for the reduction operation.
|
|
226
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
227
|
+
* elements in the linked list.
|
|
228
|
+
*/
|
|
229
|
+
reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
|
|
230
|
+
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
231
|
+
insertAfter(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
232
|
+
insertBefore(existingValueOrNode: E, newValue: E): boolean;
|
|
233
|
+
insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
234
|
+
}
|