File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/data-structures/tree/b-tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ import Comparator from '../../../utils/comparator/Comparator' ;
2
+
1
3
export default class BTreeNode {
2
4
constructor ( degree = 0 , isLeaf = true ) {
3
5
this . degree = degree ;
4
6
this . isLeaf = isLeaf ;
5
7
this . keys = new Array ( ( 2 * this . degree ) - 1 ) ;
6
8
this . children = new Array ( 2 * this . degree ) ;
7
9
this . numKeys = 0 ;
10
+ this . nodeComparator = new Comparator ( ) ;
8
11
}
9
12
10
13
traversal ( ) {
@@ -21,4 +24,18 @@ export default class BTreeNode {
21
24
}
22
25
return traverse ;
23
26
}
27
+
28
+ find ( value ) {
29
+ let i = 0 ;
30
+ while ( i < this . numKeys && value > this . keys [ i ] ) {
31
+ i += 1 ;
32
+ }
33
+ if ( this . nodeComparator . equal ( value , this . keys [ i ] ) ) {
34
+ return this ;
35
+ }
36
+ if ( this . isLeaf ) {
37
+ return null ;
38
+ }
39
+ return this . children [ i ] . find ( value ) ;
40
+ }
24
41
}
You can’t perform that action at this time.
0 commit comments