diff --git a/README.md b/README.md
index c51abe1..f427040 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,14 @@
# data-structure-typed
-![npm](https://img.shields.io/npm/v/data-structure-typed)
+
![npm](https://img.shields.io/npm/dm/data-structure-typed)
+![GitHub contributors](https://img.shields.io/github/contributors/zrwusa/data-structure-typed)
![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/data-structure-typed)
![GitHub top language](https://img.shields.io/github/languages/top/zrwusa/data-structure-typed)
![GITHUB Star](https://img.shields.io/github/stars/zrwusa/data-structure-typed)
![eslint](https://aleen42.github.io/badges/src/eslint.svg)
![NPM](https://img.shields.io/npm/l/data-structure-typed)
+![npm](https://img.shields.io/npm/v/data-structure-typed)
[//]: # (![npm bundle size](https://img.shields.io/bundlephobia/min/data-structure-typed))
@@ -939,43 +941,43 @@ We strictly adhere to computer science theory and software development standards
[//]: # (No deletion!!! Start of Replace Section)
avl-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 119.60 | 8.36 | 0.00 |
10,000 add & delete randomly | 178.17 | 5.61 | 0.00 |
10,000 addMany | 129.03 | 7.75 | 7.48e-4 |
10,000 get | 48.79 | 20.49 | 3.13e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 125.60 | 7.96 | 0.00 |
10,000 add & delete randomly | 181.22 | 5.52 | 0.00 |
10,000 addMany | 134.12 | 7.46 | 0.01 |
10,000 get | 55.08 | 18.16 | 0.01 |
binary-tree-overall
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 RBTree add | 5.80 | 172.50 | 7.88e-5 |
10,000 RBTree add & delete randomly | 16.33 | 61.24 | 0.00 |
10,000 RBTree get | 20.95 | 47.74 | 0.00 |
10,000 AVLTree add | 131.91 | 7.58 | 0.01 |
10,000 AVLTree add & delete randomly | 202.75 | 4.93 | 0.04 |
10,000 AVLTree get | 1.02 | 984.65 | 2.43e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 RBTree add | 6.17 | 161.95 | 0.00 |
10,000 RBTree add & delete randomly | 16.07 | 62.22 | 2.62e-4 |
10,000 RBTree get | 19.86 | 50.36 | 2.44e-4 |
10,000 AVLTree add | 134.38 | 7.44 | 0.02 |
10,000 AVLTree add & delete randomly | 207.20 | 4.83 | 0.06 |
10,000 AVLTree get | 0.98 | 1015.54 | 2.73e-5 |
rb-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 88.57 | 11.29 | 0.01 |
100,000 add & delete randomly | 266.59 | 3.75 | 0.06 |
100,000 getNode | 201.81 | 4.96 | 0.03 |
100,000 add & iterator | 116.38 | 8.59 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 86.65 | 11.54 | 0.02 |
100,000 add & delete randomly | 221.02 | 4.52 | 0.03 |
100,000 getNode | 190.54 | 5.25 | 0.00 |
100,000 add & iterator | 122.10 | 8.19 | 0.01 |
directed-graph
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.10 | 9751.73 | 1.85e-6 |
1,000 addEdge | 6.08 | 164.61 | 1.04e-4 |
1,000 getVertex | 0.05 | 2.17e+4 | 3.55e-7 |
1,000 getEdge | 25.95 | 38.53 | 0.01 |
tarjan | 228.15 | 4.38 | 0.01 |
topologicalSort | 187.15 | 5.34 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.11 | 8896.51 | 2.63e-5 |
1,000 addEdge | 6.53 | 153.21 | 0.00 |
1,000 getVertex | 0.05 | 2.08e+4 | 1.06e-5 |
1,000 getEdge | 27.53 | 36.33 | 0.01 |
tarjan | 224.53 | 4.45 | 0.01 |
topologicalSort | 184.02 | 5.43 | 0.00 |
hash-map
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 117.95 | 8.48 | 0.04 |
Native Map 1,000,000 set | 217.09 | 4.61 | 0.03 |
Native Set 1,000,000 add | 168.56 | 5.93 | 0.02 |
1,000,000 set & get | 121.33 | 8.24 | 0.03 |
Native Map 1,000,000 set & get | 268.81 | 3.72 | 0.02 |
Native Set 1,000,000 add & has | 172.46 | 5.80 | 0.01 |
1,000,000 ObjKey set & get | 411.49 | 2.43 | 0.09 |
Native Map 1,000,000 ObjKey set & get | 335.40 | 2.98 | 0.07 |
Native Set 1,000,000 ObjKey add & has | 287.11 | 3.48 | 0.06 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 126.27 | 7.92 | 0.05 |
Native Map 1,000,000 set | 229.80 | 4.35 | 0.03 |
Native Set 1,000,000 add | 175.83 | 5.69 | 0.01 |
1,000,000 set & get | 121.34 | 8.24 | 0.03 |
Native Map 1,000,000 set & get | 290.80 | 3.44 | 0.03 |
Native Set 1,000,000 add & has | 180.71 | 5.53 | 0.01 |
1,000,000 ObjKey set & get | 357.68 | 2.80 | 0.07 |
Native Map 1,000,000 ObjKey set & get | 310.57 | 3.22 | 0.06 |
Native Set 1,000,000 ObjKey add & has | 278.42 | 3.59 | 0.05 |
heap
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & poll | 23.77 | 42.07 | 2.92e-4 |
100,000 add & dfs | 36.94 | 27.07 | 0.01 |
10,000 fib add & pop | 374.40 | 2.67 | 0.04 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & poll | 24.85 | 40.24 | 0.00 |
100,000 add & dfs | 33.14 | 30.17 | 0.00 |
10,000 fib add & pop | 366.11 | 2.73 | 0.00 |
doubly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 235.15 | 4.25 | 0.05 |
1,000,000 unshift | 221.59 | 4.51 | 0.08 |
1,000,000 unshift & shift | 172.11 | 5.81 | 0.02 |
1,000,000 addBefore | 322.82 | 3.10 | 0.04 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 217.98 | 4.59 | 0.07 |
1,000,000 unshift | 223.20 | 4.48 | 0.08 |
1,000,000 unshift & shift | 172.87 | 5.78 | 0.03 |
1,000,000 addBefore | 387.13 | 2.58 | 0.20 |
singly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push & shift | 212.64 | 4.70 | 0.07 |
10,000 push & pop | 221.21 | 4.52 | 0.01 |
10,000 addBefore | 251.81 | 3.97 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push & shift | 225.13 | 4.44 | 0.07 |
10,000 push & pop | 234.54 | 4.26 | 0.02 |
10,000 addBefore | 252.62 | 3.96 | 0.00 |
priority-queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & poll | 75.00 | 13.33 | 9.50e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & poll | 76.49 | 13.07 | 0.00 |
deque
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 13.26 | 75.43 | 0.00 |
1,000,000 push & pop | 21.24 | 47.08 | 1.57e-4 |
100,000 push & shift | 2.20 | 453.65 | 5.13e-4 |
Native Array 100,000 push & shift | 2165.42 | 0.46 | 0.19 |
100,000 unshift & shift | 2.19 | 455.62 | 4.59e-4 |
Native Array 100,000 unshift & shift | 4298.71 | 0.23 | 0.13 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 13.20 | 75.75 | 2.79e-4 |
1,000,000 push & pop | 22.21 | 45.03 | 3.27e-4 |
100,000 push & shift | 2.26 | 442.24 | 1.43e-4 |
Native Array 100,000 push & shift | 2329.51 | 0.43 | 0.10 |
100,000 unshift & shift | 2.16 | 463.83 | 8.20e-5 |
Native Array 100,000 unshift & shift | 4590.64 | 0.22 | 0.33 |
queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 46.44 | 21.53 | 0.01 |
100,000 push & shift | 5.00 | 199.87 | 1.37e-4 |
Native Array 100,000 push & shift | 2276.16 | 0.44 | 0.12 |
Native Array 100,000 push & pop | 4.33 | 230.72 | 1.58e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 49.92 | 20.03 | 0.02 |
100,000 push & shift | 5.07 | 197.28 | 5.86e-4 |
Native Array 100,000 push & shift | 2315.78 | 0.43 | 0.13 |
Native Array 100,000 push & pop | 4.37 | 228.72 | 1.32e-4 |
stack
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 47.43 | 21.08 | 0.02 |
1,000,000 push & pop | 50.64 | 19.75 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 44.50 | 22.47 | 0.01 |
1,000,000 push & pop | 53.57 | 18.67 | 0.02 |
trie
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 47.83 | 20.91 | 0.00 |
100,000 getWords | 100.67 | 9.93 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 42.95 | 23.28 | 6.68e-4 |
100,000 getWords | 92.11 | 10.86 | 0.01 |
[//]: # (No deletion!!! End of Replace Section)
diff --git a/SPECIFICATION.md b/SPECIFICATION.md
new file mode 100644
index 0000000..539193e
--- /dev/null
+++ b/SPECIFICATION.md
@@ -0,0 +1,56 @@
+
+[NPM](https://www.npmjs.com/package/data-structure-typed)
+
+[Github](https://github.com/zrwusa/data-structure-typed)
+
+## Pain Points Addressed
+
+### Enhancing the Performance of Simulated Data Structures in JS/TS
+
+- `Queue`: While many resort to using Arrays to simulate Queues and Deques, the time complexity of Array.shift is O(n). We have tackled this challenge by implementing a Queue and Deque with O(1) time complexity for enqueue and dequeue operations.
+
+- `HashMap`: Opting for a pure HashMap over the built-in Map (technically a LinkedHashMap) can boost algorithmic speed. However, the performance is compromised due to the necessity of considering insertion order. We have independently implemented an optimized HashMap.
+
+- `Stack`: In JS, simulating a Stack with an Array is acceptable, and its performance is on par with a genuine Stack.
+
+### Introducing Missing Native Data Structures in JS/TS
+
+- `Heap / Priority Queue`: Algorithms with O(log n) time complexity have been pivotal in improving efficiency since the dawn of computers. A Heap supports insertion, deletion, and search with O(log n) time complexity, coupled with the ability to obtain the minimum / maximum value in O(1) time.
+
+- `Red Black Tree`: Developers well-versed in databases, file systems, Linux virtual memory management, and network routing tables often have a nuanced understanding of Red-Black Trees. It stands out as the least operation-intensive among all balanced binary search trees, offering optimal performance balance in CRUD operations.
+
+- `Linked List`: In scenarios where insertion or deletion of elements with O(1) time complexity is required at a specific index in an ordered collection, JS lacks a provided data structure. Hence, the need for a LinkedList to implement this functionality.
+
+- `Trie`: Efficient for fast string queries and space-efficient string storage, yet not commonly found in the standard libraries of most programming languages.
+
+- `Graph`: This data structure is not commonly found in the standard libraries of most languages, making it a non-issue in JS.
+
+## Advantages
+
+### Performance:
+
+- The performance of some ours data structures has surpassed JS's built-in data structures (`Queue`, `Deque`, `HashMap`), while most are comparable to or even surpass those in other languages. Some are still undergoing refinement (`Graph`, `AVL Tree`).
+
+### Uniformity
+
+- 1. Implementation or constraint of `forEach`, `filter`, `map`, `every`, `some`, `reduce`, `find`, `has`, `hasValue`, `get`, `print`, `isEmpty`, `clear`, `clone` methods in the base class.
+- 2. Use of generators to uniformly implement `[Symbol.iterator]`, `entries`, `keys`, `values`. Delaying iterator execution prevents performance loss and provides control during traversal.
+- 3. All deletion methods uniformly use the widely adopted `delete` in ES6, while addition methods uniformly use `add`. Compatibility with some specifications in Java.
+- 4. The first parameter for all constructors is data, and the second parameter is configuration, maintaining uniformity. The first parameter accepts any iterable type for seamless conversion between data structures.
+- 5. Uniform return types, for example, the `add` method consistently returns a boolean.
+
+### Convenience and Simplicity of APIs
+
+- Inspired by ES6, Java, ESNext, TypeScript, Python, featuring methods like `forEach`, `filter`, `map`, `every`, `some`, `reduce`, `find`, `has`, `hasValue` and `get`.
+
+### Use of Commonly Understood Industry Standard Naming
+
+- `enqueue`, `dequeue`, `push`, `pop`, `poll`, `addLast`, `addFirst`, `pollFirst`, `pollLast`, `isEmpty`, `clear`, `print`, `clone`.
+
+### Implementation of Customizable Features Whenever Possible
+
+- Such as providing callback functions (lambda expressions) for all traversal methods.
+
+### Comprehensive Documentation
+
+- The documentation not only explains the purpose of methods but also annotates time and space complexity across the entire series.
diff --git a/SPONSOR-zh-CN.md b/SPONSOR-zh-CN.md
new file mode 100644
index 0000000..5fbf74c
--- /dev/null
+++ b/SPONSOR-zh-CN.md
@@ -0,0 +1,90 @@
+
+# 我是谁
+
+我是一个拥有15年工作经验的软件开发工程师,自大学毕业职于不同行业的软件公司其中也包括一些大厂。
+
+# 目前现状
+
+为了孩子得到正规教育移居到马来西亚,持有10年居留签证,但是这个签证不允许我被马来西亚公司雇佣。
+由于自己酷爱编程,又正逢JavaScript / TypeScript (以下简称`JS/TS`)没有标准库涵盖数据结构,便决定在开源社区自己实现一套数据结构 [data-structure-typed]()。
+
+[NPM](https://www.npmjs.com/package/data-structure-typed)
+
+[Github](https://github.com/zrwusa/data-structure-typed)
+
+# 项目介绍
+
+## 最终目标
+
+- 成为JS/TS的标准库的一部分。
+
+## 解决了的痛点
+
+### 在JS / TS我们只能基于Array和Map来模拟一些数据结构,例如Queue,Deque,Stack,HashMap
+
+- `Queue`:大家使用Array来模拟Queue和Deque,但是Array.shift方法的时间复杂度是O(n)的。我们实现了入队和出队时间复杂度为O(1)的Queue,Deque。
+
+- `HashMap`:如大家希望使用一个纯正的HashMap来加速自己的算法,而不是使用内置的Map(严格来说是LinkedHashMap),由于需要顾及插入顺序所以性能上逊色于纯正的HashMap。我们单独实现了HashMap
+
+- `Stack`: 在JS中,用Array模拟Stack并没有什么不妥,性能也不弱于真正的Stack。
+
+### JS / TS内置数据结构的缺失。
+
+- `Heap / Priority Queue`:
+不得不提O(log n),这个算法时间复杂度是人类使用计算机以来最受欢迎的提高效率的方式。Heap本身就支持插入、删除、查找时间复杂度均为O(log n),
+还顺带附赠一个动态随时以O(1)的时间复杂度获取最值的功能。
+
+- `Red Black Tree`:
+相信很多了解数据库、文件系统、Linux的虚拟内存管理和网络路由表底层的开发者都对红黑树有一定了解。
+因为它是在所有平衡二叉搜索树中操作消耗量最少的,而且在CRUD这4个操作上性能平衡得最好的实现。
+
+- `Linked List`:
+例如我们需要在一个有序集合中,如果已经获取到某个元素的索引的情况下,在这个索引处插入或者删除元素,JS没有提供类似数据结构。我们需要LinkedList来实现。
+
+- `Trie`:
+字符串高速查询,字符串存储高效性方面有奇效,但是大多数编程语言的标准库中不常见。
+
+- `Graph`:
+这个数据结构在大多数的语言标准库中也不常见,所以我们不把它作为JS的弱项。
+
+
+## 优势
+
+### 性能:
+
+- 少部分数据结构的性能已经超越JS内置数据结构(`Queue`,`Deque`, `HashMap`), 大部分已接近或超越其它语言,部分还没达标(`Graph`, `AVL Tree`)
+
+### 统一性
+
+- 1、在基类中实现或约束 `forEach`,`filter`, `map`,`every`,`some`,`reduce`,`find`,`has`,`hasValue`,`get`,`print`,`isEmpty`, `clear`,`clone` 方法。
+- 2、使用生成器,统一实现`[Symbol.iterator]`,`entries`, `keys`, `values`。延迟执行遍历器以防止性能损失,并提供遍历时的可控性。
+- 3、所有的删除方法都统一采用ES6标准中惯用的`delete`。添加方法统一使用`add`。同时兼容Java中的一些规范。
+- 4、所有构造函数的第一个参数都是数据,第二个参数是配置,保持统一。第一个参数接受任意可遍历类型,以实现数据结构间自由转换。
+- 5、统一返回参数类型,如`add`方法统一返回布尔值。
+
+### APIs的便捷性和简洁性
+
+- 受ES6, Java, ESNext, TypeScript, Python的启发,如`forEach`,`filter`, `map`,`every`,`some`,`reduce`,`find`,`has`,`hasValue`,`get`
+
+### 使用通俗易懂业界常用命名
+
+- `enqueue`, `dequeue`, `push`, `pop`, `poll`, `addLast`, `addFirst`, `pollFirst`, `pollLast`, `isEmpty`, `clear`, `print`, `clone`
+
+### 尽量实现可定制化功能
+
+- 如所有遍历方法都提供回调函数(拉姆达表达式)的设计
+
+### 完善的文档
+
+- 文档不但阐述方法的用途,而且全系标注时间和空间复杂度
+
+
+## 社区活跃度
+
+- 从社区来说,NPM下载量![npm](https://img.shields.io/npm/dm/data-structure-typed),
+GitHub星星![GITHUB Star](https://img.shields.io/github/stars/zrwusa/data-structure-typed)
+贡献者![GitHub contributors](https://img.shields.io/github/contributors/zrwusa/data-structure-typed)
+
+## 赞助我们吧
+
+- 以软件工程标准来说,我们的项目目前已经达到至少75%的完整度,我们相信我们在您的赞助下很快将这个项目的完成度提高到95%,这对我的家庭来说算一种援助,对我们项目组来说是一种鼓励,也希望尽早能够实现成为`JS/TS`标准库的目标。
diff --git a/SPONSOR.md b/SPONSOR.md
new file mode 100644
index 0000000..5705dbb
--- /dev/null
+++ b/SPONSOR.md
@@ -0,0 +1,54 @@
+# Who am I
+
+I am a seasoned software development engineer with 15 years of professional experience. Following my graduation from university, I have contributed my expertise to various software companies across diverse industries, including some prominent ones.
+
+Of course, I have my flaws, I have a nerd-like attitude towards technology and could be described as a perfectionist. For instance, being excessively serious and having a penchant for studying the essence of things, I sometimes come across as a stern boss, which can be intimidating to my wife and daughter.
+
+Fortunately, my outlook on life is broad-minded. when it comes to life and family, the keywords are love, loyalty, and appreciation of beauty. I also enjoy studying cultural differences in various regions. Deep down, I actually have a bit of an artistic flair. LOL, just writing this makes me want to laugh!
+
+# Current Situation
+
+My recent move to Malaysia was motivated by the desire to provide my daughter with a formal education(Yes, you read it correctly, it is the word 'formal', because the education system in some countries is not normal), and it comes alongside holding a 10-year residency visa(MM2H). However, this visa restricts my employment opportunities within Malaysian companies. Fueled by my passion for programming and recognizing the absence of a standardized data structures library in JavaScript/TypeScript, I embarked on the journey of implementing my own set of data structures - `data-structure-typed` within the open-source community.
+
+# `data-structure-typed` Project Overview
+
+## Ultimate Goal
+
+- To seamlessly integrate into the standard library of JS/TS.
+
+## Pain Points Addressed
+
+### Enhanced the Performance of Simulated Data Structures in JS/TS
+
+- `Queue`: While many resort to using Array to simulate Queue and Deque, the time complexity of Array.shift is O(n). We have tackled this by implementing a Queue and Deque with O(1) time complexity.
+
+- `HashMap`: The built-in Map in JS is actually a LinkedHashMap, as it maintains the insertion order of elements, resulting in performance inferiority compared to a pure HashMap. We have implemented a pure HashMap.
+
+### Introducing Missing Native Data Structures in JS/TS
+
+- `Heap / Priority Queue`: Algorithms with O(log n) time complexity have been pivotal in improving efficiency since the dawn of computers. A Heap supports insertion, deletion, and search with O(log n) time complexity, coupled with the ability to obtain the minimum / maximum value in O(1) time.
+
+- `Red Black Tree`: Developers well-versed in databases, file systems, Linux virtual memory management, and network routing tables often have a nuanced understanding of Red-Black Trees. It stands out as the least operation-intensive among all balanced binary search trees, offering optimal performance balance in CRUD operations.
+
+## Advantages
+
+### Performance:
+
+- The performance of some ours data structures has surpassed JS's built-in data structures, such as `Queue`, `Deque` and `HashMap`, while most are comparable to or even surpass those in other languages. Some are still undergoing refinement, notably the `Graph` and `AVL Tree`.
+
+### Uniformity
+
+- 1. Concise and industry-standard naming:Implementation or constraint of `forEach`, `filter`, `map`, `every`, `some`, `reduce`, `find`, `has`, `hasValue`, `get`, `print`, `isEmpty`, `clear`, `clone` methods in the base class.
+- 2. Adhere to the ES6 specification: Use of generators to uniformly implement `[Symbol.iterator]`, `entries`, `keys`, `values`. Delaying iterator execution prevents performance loss and provides control during traversal. All deletion methods uniformly use the widely adopted `delete` in ES6, while addition methods uniformly use `add`. Compatibility with some specifications in Java.
+- 3. Constructors:The first parameter for all constructors is data, and the second parameter is configuration, maintaining uniformity. The first parameter accepts any iterable type for seamless conversion between data structures.
+- 4. Return types:for example, the `add` method consistently returns a boolean.
+
+We would like to provide a more detailed description of this project, but space is limited here. For specific technical details, please refer to the [README.md](https://github.com/zrwusa/data-structure-typed), [SPECIFICATION.md](https://github.com/zrwusa/data-structure-typed/blob/main/CODE_OF_CONDUCT.md), or [API Docs](https://data-structure-typed-docs.vercel.app/).
+
+## Community Activity
+
+- In terms of community engagement, we have noteworthy metrics including NPM download count ![npm](https://img.shields.io/npm/dm/data-structure-typed), GitHub stars ![GITHUB Star](https://img.shields.io/github/stars/zrwusa/data-structure-typed), and contributors ![GitHub contributors](https://img.shields.io/github/contributors/zrwusa/data-structure-typed).
+
+## Sponsor Us
+
+- From a software engineering standards perspective, our project has achieved at least 75% completeness. With your sponsorship, we believe we can swiftly elevate the project's completion to 95%, providing valuable assistance to my family and serving as encouragement to our project team. Additionally, we aspire to expedite the goal of becoming an integral part of the `JS/TS` standard library.
diff --git a/src/data-structures/base/iterable-base.ts b/src/data-structures/base/iterable-base.ts
index 35d6083..fbfff56 100644
--- a/src/data-structures/base/iterable-base.ts
+++ b/src/data-structures/base/iterable-base.ts
@@ -289,8 +289,14 @@ export abstract class IterableEntryBase {
abstract isEmpty(): boolean;
+ abstract clear(): void;
+
abstract clone(): any;
+ abstract map(...args: any[]): any;
+
+ abstract filter(...args: any[]): any;
+
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
}
@@ -497,7 +503,13 @@ export abstract class IterableElementBase {
abstract isEmpty(): boolean;
+ abstract clear(): void;
+
abstract clone(): C;
+ abstract map(...args: any[]): any;
+
+ abstract filter(...args: any[]): any;
+
protected abstract _getIterator(...args: any[]): IterableIterator;
}
diff --git a/src/data-structures/graph/directed-graph.ts b/src/data-structures/graph/directed-graph.ts
index fbaf26d..4bc5afe 100644
--- a/src/data-structures/graph/directed-graph.ts
+++ b/src/data-structures/graph/directed-graph.ts
@@ -616,6 +616,23 @@ export class DirectedGraph<
return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
}
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ */
+
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ *
+ * The clear function resets the vertex map, in-edge map, and out-edge map.
+ */
+ clear() {
+ this._vertexMap = new Map();
+ this._inEdgeMap = new Map();
+ this._outEdgeMap = new Map();
+ }
+
/**
* The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
*
diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts
index 86b29e2..2a6fdde 100644
--- a/src/data-structures/graph/undirected-graph.ts
+++ b/src/data-structures/graph/undirected-graph.ts
@@ -377,6 +377,22 @@ export class UndirectedGraph<
return this.vertexMap.size === 0 && this.edgeMap.size === 0;
}
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ */
+
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ *
+ * The clear function resets the vertex and edge maps to empty maps.
+ */
+ clear() {
+ this._vertexMap = new Map();
+ this._edgeMap = new Map();
+ }
+
/**
* The clone function creates a new UndirectedGraph object and copies the
* vertexMap and edgeMap from this graph to the new one. This is done by
diff --git a/src/data-structures/tree/tree.ts b/src/data-structures/tree/tree.ts
index 9cf04da..c0e85e5 100644
--- a/src/data-structures/tree/tree.ts
+++ b/src/data-structures/tree/tree.ts
@@ -15,10 +15,10 @@ export class TreeNode {
this._children = children || [];
}
- private _key: string;
+ protected _key: string;
/**
- * The function returns the value of the private variable _key.
+ * The function returns the value of the protected variable _key.
* @returns The value of the `_key` property, which is a string.
*/
get key(): string {
@@ -26,7 +26,7 @@ export class TreeNode {
}
/**
- * The above function sets the value of a private variable called "key".
+ * The above function sets the value of a protected variable called "key".
* @param {string} value - The value parameter is a string that represents the value to be assigned
* to the key.
*/
@@ -34,7 +34,7 @@ export class TreeNode {
this._key = value;
}
- private _value?: V | undefined;
+ protected _value?: V | undefined;
/**
* The function returns the value stored in a variable, or undefined if the variable is empty.
@@ -53,7 +53,7 @@ export class TreeNode {
this._value = value;
}
- private _children?: TreeNode[] | undefined;
+ protected _children?: TreeNode[] | undefined;
/**
* The function returns an array of TreeNode objects or undefined.
diff --git a/src/data-structures/trie/trie.ts b/src/data-structures/trie/trie.ts
index 8f19808..6844431 100644
--- a/src/data-structures/trie/trie.ts
+++ b/src/data-structures/trie/trie.ts
@@ -22,7 +22,7 @@ export class TrieNode {
protected _key: string;
/**
- * The function returns the value of the private variable _key.
+ * The function returns the value of the protected variable _key.
* @returns The value of the `_key` property, which is a string.
*/
get key(): string {
@@ -30,7 +30,7 @@ export class TrieNode {
}
/**
- * The above function sets the value of a private variable called "key".
+ * The above function sets the value of a protected variable called "key".
* @param {string} value - The value parameter is a string that represents the value to be assigned
* to the key.
*/
@@ -214,6 +214,22 @@ export class Trie extends IterableElementBase {
return this.size === 0;
}
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ */
+
+ /**
+ * Time Complexity: O(1)
+ * Space Complexity: O(1)
+ *
+ * The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
+ */
+ clear(): void {
+ this._size = 0;
+ this._root = new TrieNode('');
+ }
+
/**
* Time Complexity: O(l), where l is the length of the word being deleted.
* Space Complexity: O(n) - Due to the recursive DFS approach.
diff --git a/test/unit/data-structures/graph/abstract-graph.test.ts b/test/unit/data-structures/graph/abstract-graph.test.ts
index 2baa63d..d53105b 100644
--- a/test/unit/data-structures/graph/abstract-graph.test.ts
+++ b/test/unit/data-structures/graph/abstract-graph.test.ts
@@ -81,6 +81,9 @@ class MyGraph<
return true;
}
+ clear(): void {
+ }
+
clone(): any {
return {};
}