diff --git a/CHANGELOG.md b/CHANGELOG.md
index b217769..3d67efd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
-## [v1.47.0](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
+## [v1.47.1](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
### Changes
diff --git a/README.md b/README.md
index d103bbe..9826e8a 100644
--- a/README.md
+++ b/README.md
@@ -73,46 +73,46 @@ const {
## Vivid Examples
### Binary Tree
-[Try it out](https://vivid-algorithm.vercel.app/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/), or you can run your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/binary-tree-array-to-binary-tree.webp)
### Binary Tree DFS
-[Try it out](https://vivid-algorithm.vercel.app/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/binary-tree-dfs-in-order.webp)
### AVL Tree
-[Try it out](https://vivid-algorithm.vercel.app/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/avl-tree-test.webp)
### Tree Multi Map
-[Try it out](https://vivid-algorithm.vercel.app/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/tree-multiset-test.webp)
### Matrix
-[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/matrix-cut-off-tree-for-golf.webp)
### Directed Graph
-[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/directed-graph-test.webp)
### Map Graph
-[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/), or you can execute your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm)
+[Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/)
![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/map-graph-test.webp)
@@ -288,8 +288,7 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
Data Structure |
Unit Test |
Performance Test |
-API Documentation |
-Implemented |
+API Docs |
@@ -298,168 +297,126 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
|
|
Binary Tree |
- |
Binary Search Tree (BST) |
|
|
BST |
- |
AVL Tree |
|
|
AVLTree |
- |
Red Black Tree |
|
|
RedBlackTree |
- |
Tree Multiset |
|
|
TreeMultimap |
- |
Segment Tree |
|
|
SegmentTree |
- |
Binary Indexed Tree |
|
|
BinaryIndexedTree |
- |
-
-
-Graph |
- |
- |
-AbstractGraph |
- |
-
-
-Directed Graph |
- |
- |
-DirectedGraph |
- |
-
-
-Undirected Graph |
- |
- |
-UndirectedGraph |
- |
-
-
-Linked List |
- |
- |
-SinglyLinkedList |
- |
-
-
-Singly Linked List |
- |
- |
-SinglyLinkedList |
- |
-
-
-Doubly Linked List |
- |
- |
-DoublyLinkedList |
- |
-
-
-Queue |
- |
- |
-Queue |
- |
-
-
-Object Deque |
- |
- |
-ObjectDeque |
- |
-
-
-Array Deque |
- |
- |
-ArrayDeque |
- |
-
-
-Stack |
- |
- |
-Stack |
- |
-
-
-Coordinate Set |
- |
- |
-CoordinateSet |
- |
-
-
-Coordinate Map |
- |
- |
-CoordinateMap |
- |
Heap |
|
|
Heap |
- |
Priority Queue |
|
|
PriorityQueue |
- |
Max Priority Queue |
|
|
MaxPriorityQueue |
- |
Min Priority Queue |
|
|
MinPriorityQueue |
- |
Trie |
|
|
Trie |
+
+
+Graph |
|
+ |
+AbstractGraph |
+
+
+Directed Graph |
+ |
+ |
+DirectedGraph |
+
+
+Undirected Graph |
+ |
+ |
+UndirectedGraph |
+
+
+Queue |
+ |
+ |
+Queue |
+
+
+Deque |
+ |
+ |
+Deque |
+
+
+Linked List |
+ |
+ |
+SinglyLinkedList |
+
+
+Singly Linked List |
+ |
+ |
+SinglyLinkedList |
+
+
+Doubly Linked List |
+ |
+ |
+DoublyLinkedList |
+
+
+Stack |
+ |
+ |
+Stack |
@@ -476,42 +433,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
-
- DoublyLinkedList<E> |
- list<T> |
- LinkedList<E> |
- deque |
-
-
- SinglyLinkedList<E> |
- - |
- - |
- - |
-
-
- Array<E> |
- vector<T> |
- ArrayList<E> |
- list |
-
-
- Queue<E> |
- queue<T> |
- Queue<E> |
- - |
-
-
- Deque<E> |
- deque<T> |
- - |
- - |
-
-
- PriorityQueue<E> |
- priority_queue<T> |
- PriorityQueue<E> |
- - |
-
Heap<E> |
priority_queue<T> |
@@ -519,27 +440,15 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
heapq |
- Stack<E> |
- stack<T> |
- Stack<E> |
- - |
+ Deque<E> |
+ deque<T> |
+ ArrayDeque<E> |
+ deque |
- Set<E> |
- set<T> |
- HashSet<E> |
- set |
-
-
- Map<K, V> |
- map<K, V> |
- HashMap<K, V> |
- dict |
-
-
- - |
- unordered_set<T> |
- HashSet<E> |
+ Queue<E> |
+ queue<T> |
+ Queue<E> |
- |
@@ -549,10 +458,16 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
defaultdict |
- Map<K, V> |
+ DoublyLinkedList<E> |
+ list<T> |
+ LinkedList<E> |
+ - |
+
+
+ SinglyLinkedList<E> |
+ - |
- |
- |
- OrderedDict |
BinaryTree<K, V> |
@@ -566,6 +481,18 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
- |
- |
+
+ RedBlackTree<E> |
+ set<T> |
+ TreeSet<E> |
+ - |
+
+
+ RedBlackTree<K, V> |
+ map<K, V> |
+ TreeMap<K, V> |
+ - |
+
TreeMultimap<K, V> |
multimap<K, V> |
@@ -573,21 +500,9 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
- |
- AVLTree<E> |
- |
- TreeSet<E> |
+ multiset<T> |
- |
-
-
- AVLTree<K, V> |
- - |
- TreeMap<K, V> |
- - |
-
-
- AVLTree<E> |
- set |
- TreeSet<E> |
- |
@@ -596,12 +511,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
- |
- |
-
- - |
- multiset<T> |
- - |
- - |
-
DirectedGraph<V, E> |
- |
@@ -614,6 +523,48 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
- |
- |
+
+ PriorityQueue<E> |
+ priority_queue<T> |
+ PriorityQueue<E> |
+ - |
+
+
+ Array<E> |
+ vector<T> |
+ ArrayList<E> |
+ list |
+
+
+ Stack<E> |
+ stack<T> |
+ Stack<E> |
+ - |
+
+
+ Set<E> |
+ - |
+ HashSet<E> |
+ set |
+
+
+ Map<K, V> |
+ - |
+ HashMap<K, V> |
+ dict |
+
+
+ - |
+ unordered_set<T> |
+ HashSet<E> |
+ - |
+
+
+ Map<K, V> |
+ - |
+ - |
+ OrderedDict |
+
- |
unordered_multiset |
@@ -627,7 +578,7 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
- |
- - |
+ HashMap<K, V> |
- |
LinkedHashMap<K, V> |
- |
diff --git a/src/data-structures/hash/hash-map.ts b/src/data-structures/hash/hash-map.ts
index c7a0d4d..bf40be1 100644
--- a/src/data-structures/hash/hash-map.ts
+++ b/src/data-structures/hash/hash-map.ts
@@ -305,6 +305,14 @@ export class HashMap {
}
}
+ /**
+ * The `filter` function takes a predicate function and returns a new HashMap containing only the
+ * key-value pairs that satisfy the predicate.
+ * @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
+ * `map`.
+ * @returns a new HashMap object that contains the key-value pairs from the original HashMap that
+ * satisfy the given predicate function.
+ */
filter(predicate: (element: [K, V], map: HashMap) => boolean): HashMap {
const filteredMap = new HashMap();
for (const [key, value] of this) {
@@ -315,6 +323,13 @@ export class HashMap {
return filteredMap;
}
+ /**
+ * The `map` function takes a callback function and returns a new HashMap with the values transformed
+ * by the callback.
+ * @param callback - The `callback` parameter is a function that takes two arguments: `element` and
+ * `map`.
+ * @returns a new HashMap object with the values mapped according to the provided callback function.
+ */
map(callback: (element: [K, V], map: HashMap) => NV): HashMap {
const mappedMap = new HashMap();
for (const [key, value] of this) {
@@ -324,6 +339,18 @@ export class HashMap {
return mappedMap;
}
+ /**
+ * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
+ * each element, accumulating a single value.
+ * @param callback - The callback parameter is a function that takes three arguments: accumulator,
+ * element, and map. It is called for each element in the HashMap and is used to accumulate a single
+ * result.
+ * @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
+ * is the value that will be passed as the first argument to the `callback` function when reducing
+ * the elements of the map.
+ * @returns The `reduce` function is returning the final value of the accumulator after iterating
+ * over all the elements in the HashMap and applying the callback function to each element.
+ */
reduce(callback: (accumulator: A, element: [K, V], map: HashMap) => A, initialValue: A): A {
let accumulator = initialValue;
for (const element of this) {