data-structure-typed 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +3 -0
- package/CHANGELOG.md +1 -1
- package/MIGRATION.md +48 -0
- package/README.md +20 -2
- package/README_CN.md +20 -2
- package/SPECIFICATION.md +24 -0
- package/SPECIFICATION.zh-CN.md +24 -0
- package/dist/cjs/binary-tree.cjs +1897 -19
- package/dist/cjs/graph.cjs +174 -0
- package/dist/cjs/hash.cjs +33 -0
- package/dist/cjs/heap.cjs +71 -0
- package/dist/cjs/index.cjs +2383 -3
- package/dist/cjs/linked-list.cjs +224 -2
- package/dist/cjs/matrix.cjs +24 -0
- package/dist/cjs/priority-queue.cjs +71 -0
- package/dist/cjs/queue.cjs +221 -1
- package/dist/cjs/stack.cjs +59 -0
- package/dist/cjs/trie.cjs +62 -0
- package/dist/cjs-legacy/binary-tree.cjs +1897 -19
- package/dist/cjs-legacy/graph.cjs +174 -0
- package/dist/cjs-legacy/hash.cjs +33 -0
- package/dist/cjs-legacy/heap.cjs +71 -0
- package/dist/cjs-legacy/index.cjs +2383 -3
- package/dist/cjs-legacy/linked-list.cjs +224 -2
- package/dist/cjs-legacy/matrix.cjs +24 -0
- package/dist/cjs-legacy/priority-queue.cjs +71 -0
- package/dist/cjs-legacy/queue.cjs +221 -1
- package/dist/cjs-legacy/stack.cjs +59 -0
- package/dist/cjs-legacy/trie.cjs +62 -0
- package/dist/esm/binary-tree.mjs +1897 -19
- package/dist/esm/graph.mjs +174 -0
- package/dist/esm/hash.mjs +33 -0
- package/dist/esm/heap.mjs +71 -0
- package/dist/esm/index.mjs +2383 -3
- package/dist/esm/linked-list.mjs +224 -2
- package/dist/esm/matrix.mjs +24 -0
- package/dist/esm/priority-queue.mjs +71 -0
- package/dist/esm/queue.mjs +221 -1
- package/dist/esm/stack.mjs +59 -0
- package/dist/esm/trie.mjs +62 -0
- package/dist/esm-legacy/binary-tree.mjs +1897 -19
- package/dist/esm-legacy/graph.mjs +174 -0
- package/dist/esm-legacy/hash.mjs +33 -0
- package/dist/esm-legacy/heap.mjs +71 -0
- package/dist/esm-legacy/index.mjs +2383 -3
- package/dist/esm-legacy/linked-list.mjs +224 -2
- package/dist/esm-legacy/matrix.mjs +24 -0
- package/dist/esm-legacy/priority-queue.mjs +71 -0
- package/dist/esm-legacy/queue.mjs +221 -1
- package/dist/esm-legacy/stack.mjs +59 -0
- package/dist/esm-legacy/trie.mjs +62 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +90 -1
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/umd/data-structure-typed.js +2383 -3
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +14 -10
- package/jest.integration.config.js +1 -2
- package/package.json +9 -7
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +36 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
- package/src/data-structures/binary-tree/binary-tree.ts +75 -0
- package/src/data-structures/binary-tree/bst.ts +72 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +375 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
- package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
- package/src/data-structures/binary-tree/tree-set.ts +492 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +33 -0
- package/src/data-structures/heap/heap.ts +42 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
- package/src/data-structures/matrix/matrix.ts +24 -0
- package/src/data-structures/queue/deque.ts +103 -1
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +36 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v2.
|
|
11
|
+
## [v2.6.0](https://github.com/zrwusa/data-structure-typed/compare/v2.5.3...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
## [v2.5.3](https://github.com/zrwusa/data-structure-typed/compare/v2.5.1...v2.5.3) (31 March 2026)
|
|
14
14
|
|
package/MIGRATION.md
CHANGED
|
@@ -124,10 +124,58 @@ heap.deleteBy(e => e.id === 42);
|
|
|
124
124
|
heap.deleteWhere(e => e.id === 42);
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
#### `DoublyLinkedList.getBackward()` → use `findLast()`
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// Deprecated
|
|
131
|
+
list.getBackward(node => node.value > 5);
|
|
132
|
+
|
|
133
|
+
// Preferred (aligns with ES2023 Array.findLast)
|
|
134
|
+
list.findLast(node => node.value > 5);
|
|
135
|
+
```
|
|
136
|
+
|
|
127
137
|
---
|
|
128
138
|
|
|
129
139
|
### New Features
|
|
130
140
|
|
|
141
|
+
#### Array-Compatible APIs (v2.5.4+)
|
|
142
|
+
|
|
143
|
+
All `IterableElementBase` containers (Queue, Deque, Stack, LinkedList, Heap, Trie) now support:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
structure.includes(element); // alias for has()
|
|
147
|
+
[...structure.entries()]; // [[0, val0], [1, val1], ...]
|
|
148
|
+
[...structure.keys()]; // [0, 1, 2, ...]
|
|
149
|
+
structure.toReversed(); // new instance, reversed (linear containers)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Back-to-Front Search (v2.5.4+)
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Deque + DoublyLinkedList
|
|
156
|
+
deque.findLast(v => v > 10); // last matching value
|
|
157
|
+
deque.findLastIndex(v => v > 10); // last matching index, or -1
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### TreeSet ES2025 Set Operations (v2.5.4+)
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const a = new TreeSet([1, 2, 3, 4, 5]);
|
|
164
|
+
const b = new TreeSet([3, 4, 5, 6, 7]);
|
|
165
|
+
|
|
166
|
+
a.union(b); // TreeSet [1,2,3,4,5,6,7]
|
|
167
|
+
a.intersection(b); // TreeSet [3,4,5]
|
|
168
|
+
a.difference(b); // TreeSet [1,2]
|
|
169
|
+
a.symmetricDifference(b); // TreeSet [1,2,6,7]
|
|
170
|
+
a.isSubsetOf(b); // false
|
|
171
|
+
a.isSupersetOf(b); // false
|
|
172
|
+
a.isDisjointFrom(b); // false
|
|
173
|
+
|
|
174
|
+
// Works with any Iterable
|
|
175
|
+
a.union([10, 11]);
|
|
176
|
+
a.intersection(new Set([2, 4]));
|
|
177
|
+
```
|
|
178
|
+
|
|
131
179
|
#### `deleteWhere()` — conditional deletion
|
|
132
180
|
|
|
133
181
|
Available on: `TreeMap`, `TreeSet`, `TreeMultiMap`, `TreeMultiSet`, `DoublyLinkedList`, `Queue`, `Heap`
|
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
English | [简体中文](./README_CN.md)
|
|
4
4
|
|
|
5
|
-
A production-ready TypeScript data structures library featuring **Heap,
|
|
5
|
+
A production-ready TypeScript data structures library featuring **Heap, Linked List, Deque, Trie, Graph, Red-Black Tree, TreeMap, TreeSet, SkipList, Segment Tree**, and more — with APIs that align with JavaScript's native **Array, Map, and Set**. Zero dependencies. Type-safe. ES2025 Set operations. O(log n) rank & range queries.
|
|
6
6
|
|
|
7
|
-
> **Looking for a TreeMap or
|
|
7
|
+
> **Looking for a TreeMap, TreeSet, or PriorityQueue in TypeScript/JavaScript?** Familiar API, set operations, rank queries, sorted access — no more repeated `Array.sort()`.
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|

|
|
@@ -362,6 +362,24 @@ taskQueue.add({ priority: 9, task: 'Alert' }); // Instant priority handling
|
|
|
362
362
|
const nextTask = taskQueue.pop(); // { priority: 9, task: 'Alert' }
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
### Set Operations (ES2025)
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { TreeSet } from 'data-structure-typed';
|
|
369
|
+
|
|
370
|
+
const a = new TreeSet([1, 2, 3, 4, 5]);
|
|
371
|
+
const b = new TreeSet([3, 4, 5, 6, 7]);
|
|
372
|
+
|
|
373
|
+
[...a.union(b)]; // [1,2,3,4,5,6,7]
|
|
374
|
+
[...a.intersection(b)]; // [3,4,5]
|
|
375
|
+
[...a.difference(b)]; // [1,2]
|
|
376
|
+
[...a.symmetricDifference(b)]; // [1,2,6,7]
|
|
377
|
+
a.isSubsetOf(b); // false
|
|
378
|
+
|
|
379
|
+
// Works with any Iterable — native Set, arrays, generators
|
|
380
|
+
a.intersection(new Set([2, 4, 6])); // TreeSet [2, 4]
|
|
381
|
+
```
|
|
382
|
+
|
|
365
383
|
### Fast Queue (FIFO)
|
|
366
384
|
|
|
367
385
|
```typescript
|
package/README_CN.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.md) | 简体中文
|
|
4
4
|
|
|
5
|
-
一个生产就绪的 TypeScript
|
|
5
|
+
一个生产就绪的 TypeScript 数据结构库,包含 **Heap、Linked List、Deque、Trie、Graph、Red-Black Tree、TreeMap、TreeSet、SkipList、Segment Tree** 等 — API 对齐 JavaScript 原生 **Array、Map 和 Set**。零依赖。类型安全。ES2025 Set 操作。O(log n) 排名和范围查询。
|
|
6
6
|
|
|
7
|
-
> **在 JavaScript 中寻找 TreeMap 或
|
|
7
|
+
> **在 TypeScript/JavaScript 中寻找 TreeMap、TreeSet 或 PriorityQueue?** 熟悉的 API、集合操作、排名查询、有序访问 — 告别重复 `Array.sort()`。
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|

|
|
@@ -362,6 +362,24 @@ taskQueue.add({ priority: 9, task: 'Alert' }); // 即时优先级处理
|
|
|
362
362
|
const nextTask = taskQueue.pop(); // { priority: 9, task: 'Alert' }
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
### 集合操作 (ES2025)
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { TreeSet } from 'data-structure-typed';
|
|
369
|
+
|
|
370
|
+
const a = new TreeSet([1, 2, 3, 4, 5]);
|
|
371
|
+
const b = new TreeSet([3, 4, 5, 6, 7]);
|
|
372
|
+
|
|
373
|
+
[...a.union(b)]; // [1,2,3,4,5,6,7]
|
|
374
|
+
[...a.intersection(b)]; // [3,4,5]
|
|
375
|
+
[...a.difference(b)]; // [1,2]
|
|
376
|
+
[...a.symmetricDifference(b)]; // [1,2,6,7]
|
|
377
|
+
a.isSubsetOf(b); // false
|
|
378
|
+
|
|
379
|
+
// 支持任意 Iterable — 原生 Set、数组、生成器
|
|
380
|
+
a.intersection(new Set([2, 4, 6])); // TreeSet [2, 4]
|
|
381
|
+
```
|
|
382
|
+
|
|
365
383
|
### 快速队列 (FIFO)
|
|
366
384
|
|
|
367
385
|
```typescript
|
package/SPECIFICATION.md
CHANGED
|
@@ -116,6 +116,16 @@ structure.peek(): T | undefined // View front element (Queue/Deque/S
|
|
|
116
116
|
structure.first: T | undefined // View first element (getter)
|
|
117
117
|
structure.last: T | undefined // View last element (getter)
|
|
118
118
|
|
|
119
|
+
// Search (back-to-front)
|
|
120
|
+
structure.findLast(pred: Function): T | undefined // Deque, DoublyLinkedList
|
|
121
|
+
structure.findLastIndex(pred: Function): number // Deque, DoublyLinkedList
|
|
122
|
+
|
|
123
|
+
// Array-compatible (migration helpers)
|
|
124
|
+
structure.includes(element: T): boolean // Alias for has()
|
|
125
|
+
structure.entries(): IterableIterator<[number, T]> // [index, value] pairs
|
|
126
|
+
structure.keys(): IterableIterator<number> // Index iterator
|
|
127
|
+
structure.toReversed(): this // Non-mutating reverse (new instance)
|
|
128
|
+
|
|
119
129
|
// Size and queries
|
|
120
130
|
structure.size: number // Element count (Stack, Trie, etc.)
|
|
121
131
|
structure.length: number // Element count (Queue, Deque, LinkedList)
|
|
@@ -167,6 +177,20 @@ heap.size: number
|
|
|
167
177
|
heap.isEmpty(): boolean
|
|
168
178
|
```
|
|
169
179
|
|
|
180
|
+
### TreeSet — ES2025 Set Operations
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
treeSet.union(other: Iterable<K>): TreeSet<K>
|
|
184
|
+
treeSet.intersection(other: Iterable<K>): TreeSet<K>
|
|
185
|
+
treeSet.difference(other: Iterable<K>): TreeSet<K>
|
|
186
|
+
treeSet.symmetricDifference(other: Iterable<K>): TreeSet<K>
|
|
187
|
+
treeSet.isSubsetOf(other: Iterable<K>): boolean
|
|
188
|
+
treeSet.isSupersetOf(other: Iterable<K>): boolean
|
|
189
|
+
treeSet.isDisjointFrom(other: Iterable<K>): boolean
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
All accept any `Iterable<K>` (TreeSet, native Set, Array, generators).
|
|
193
|
+
|
|
170
194
|
### Array Methods (Available on All Structures)
|
|
171
195
|
|
|
172
196
|
**All structures support ES6+ array methods via iteration:**
|
package/SPECIFICATION.zh-CN.md
CHANGED
|
@@ -116,6 +116,16 @@ structure.peek(): T | undefined // 查看队头元素(Queue/Deque/
|
|
|
116
116
|
structure.first: T | undefined // 查看第一个元素(getter)
|
|
117
117
|
structure.last: T | undefined // 查看最后一个元素(getter)
|
|
118
118
|
|
|
119
|
+
// 反向查找
|
|
120
|
+
structure.findLast(pred: Function): T | undefined // Deque、DoublyLinkedList
|
|
121
|
+
structure.findLastIndex(pred: Function): number // Deque、DoublyLinkedList
|
|
122
|
+
|
|
123
|
+
// Array 兼容(方便迁移)
|
|
124
|
+
structure.includes(element: T): boolean // has() 的别名
|
|
125
|
+
structure.entries(): IterableIterator<[number, T]> // [index, value] 对
|
|
126
|
+
structure.keys(): IterableIterator<number> // 索引迭代器
|
|
127
|
+
structure.toReversed(): this // 非破坏性反转(返回新实例)
|
|
128
|
+
|
|
119
129
|
// 大小和查询
|
|
120
130
|
structure.size: number // 元素数量(Stack、Trie 等)
|
|
121
131
|
structure.length: number // 元素数量(Queue、Deque、LinkedList)
|
|
@@ -167,6 +177,20 @@ heap.size: number
|
|
|
167
177
|
heap.isEmpty(): boolean
|
|
168
178
|
```
|
|
169
179
|
|
|
180
|
+
### TreeSet — ES2025 集合操作
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
treeSet.union(other: Iterable<K>): TreeSet<K> // 并集
|
|
184
|
+
treeSet.intersection(other: Iterable<K>): TreeSet<K> // 交集
|
|
185
|
+
treeSet.difference(other: Iterable<K>): TreeSet<K> // 差集
|
|
186
|
+
treeSet.symmetricDifference(other: Iterable<K>): TreeSet<K>// 对称差集
|
|
187
|
+
treeSet.isSubsetOf(other: Iterable<K>): boolean // 子集判断
|
|
188
|
+
treeSet.isSupersetOf(other: Iterable<K>): boolean // 超集判断
|
|
189
|
+
treeSet.isDisjointFrom(other: Iterable<K>): boolean // 不相交判断
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
接受任何 `Iterable<K>`(TreeSet、原生 Set、数组、生成器)。
|
|
193
|
+
|
|
170
194
|
### 数组方法(所有结构上可用)
|
|
171
195
|
|
|
172
196
|
**所有结构通过迭代支持 ES6+ 数组方法:**
|