You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,9 @@ Binary Search Tree & AVL Tree (Self Balancing Tree) implementation in javascript
15
15
*[constructor](#constructor)
16
16
*[insert](#insert)
17
17
*[has](#has)
18
+
*[hasKey](#haskey)
18
19
*[find](#find)
20
+
*[findKey](#findkey)
19
21
*[min](#min)
20
22
*[max](#max)
21
23
*[lowerBound (floor)](#lowerbound-floor)
@@ -70,6 +72,8 @@ the compare function must return a number for the 3 cases:
70
72
71
73
There is already a default compare function for primitive values (number, string).
72
74
75
+
constructor also accepts an options param, where the comparison key prob name can be passed for object types in order to search by that key directly using findKey and hasKey.
76
+
73
77
##### JS
74
78
###### BinarySearchTree
75
79
```js
@@ -80,7 +84,7 @@ const employees = new BinarySearchTree((a, b) => a.id - b.id);
80
84
###### AvlTree
81
85
```js
82
86
constnums=newAvlTree();
83
-
constemployees=newAvlTree((a, b) =>a.id-b.id);
87
+
constemployees=newAvlTree((a, b) =>a.id-b.id, { key:'id' });
84
88
```
85
89
86
90
##### TS
@@ -93,13 +97,13 @@ interface IEmployee {
93
97
###### BinarySearchTree
94
98
```js
95
99
constnums=newBinarySearchTree<number>();
96
-
constemployees=newBinarySearchTree<IEmployee>((a, b) =>a.id-b.id);
100
+
constemployees=newBinarySearchTree<IEmployee>((a, b) =>a.id-b.id, { key:'id' });
97
101
```
98
102
99
103
###### AvlTree
100
104
```js
101
105
constnums=newAvlTree<number>();
102
-
constemployees=newAvlTree<IEmployee>((a, b) =>a.id-b.id);
106
+
constemployees=newAvlTree<IEmployee>((a, b) =>a.id-b.id, { key:'id' });
0 commit comments