File tree 11 files changed +20
-45
lines changed
11 files changed +20
-45
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
import rotate_left from '../rotate/rotate_left.js' ;
7
6
import rotate_right from '../rotate/rotate_right.js' ;
8
7
import sibling from '../family/sibling.js' ;
@@ -17,10 +16,10 @@ import delete_case4 from './delete_case4.js';
17
16
* - all other root-leaf paths have a black height of b
18
17
* - n is not the root
19
18
*
20
- * @param {Node|Leaf } n - The input node.
19
+ * @param {Node } n - The input node.
21
20
*/
22
21
const delete_case2 = ( n ) => {
23
- assert ( n instanceof Node || n instanceof Leaf ) ;
22
+ assert ( n instanceof Node ) ;
24
23
assert ( n . _color === BLACK ) ;
25
24
assert ( n . parent !== null ) ;
26
25
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
import sibling from '../family/sibling.js' ;
7
6
8
7
import delete_case1 from './delete_case1.js' ;
@@ -16,10 +15,10 @@ import delete_case4 from './delete_case4.js';
16
15
* - n is not the root
17
16
* - n's sibling is black
18
17
*
19
- * @param {Node|Leaf } n - The input node.
18
+ * @param {Node } n - The input node.
20
19
*/
21
20
const delete_case3 = ( n ) => {
22
- assert ( n instanceof Node || n instanceof Leaf ) ;
21
+ assert ( n instanceof Node ) ;
23
22
assert ( n . _color === BLACK ) ;
24
23
assert ( n . parent !== null ) ;
25
24
const s = sibling ( n ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
import sibling from '../family/sibling.js' ;
7
6
8
7
import delete_case5 from './delete_case5.js' ;
@@ -16,10 +15,10 @@ import delete_case5 from './delete_case5.js';
16
15
* - n's sibling is black
17
16
* - n's parent and n's sibling's children cannot all be black
18
17
*
19
- * @param {Node|Leaf } n - The input node.
18
+ * @param {Node } n - The input node.
20
19
*/
21
20
const delete_case4 = ( n ) => {
22
- assert ( n instanceof Node || n instanceof Leaf ) ;
21
+ assert ( n instanceof Node ) ;
23
22
assert ( n . _color === BLACK ) ;
24
23
assert ( n . parent !== null ) ;
25
24
const s = sibling ( n ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
import rotate_left from '../rotate/rotate_left.js' ;
7
6
import rotate_right from '../rotate/rotate_right.js' ;
8
7
import sibling from '../family/sibling.js' ;
@@ -18,10 +17,10 @@ import delete_case6 from './delete_case6.js';
18
17
* - n's sibling is black
19
18
* - at least one of n's sibling's children is red
20
19
*
21
- * @param {Node|Leaf } n - The input node.
20
+ * @param {Node } n - The input node.
22
21
*/
23
22
const delete_case5 = ( n ) => {
24
- assert ( n instanceof Node || n instanceof Leaf ) ;
23
+ assert ( n instanceof Node ) ;
25
24
assert ( n . _color === BLACK ) ;
26
25
assert ( n . parent !== null ) ;
27
26
const s = sibling ( n ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
import rotate_left from '../rotate/rotate_left.js' ;
7
6
import rotate_right from '../rotate/rotate_right.js' ;
8
7
import sibling from '../family/sibling.js' ;
@@ -17,10 +16,10 @@ import sibling from '../family/sibling.js';
17
16
* - if n is a left child, the right child of n's sibling is red
18
17
* - if n is a right child, the left child of n's sibling is red
19
18
*
20
- * @param {Node|Leaf } n - The input node.
19
+ * @param {Node } n - The input node.
21
20
*/
22
21
const delete_case6 = ( n ) => {
23
- assert ( n instanceof Node || n instanceof Leaf ) ;
22
+ assert ( n instanceof Node ) ;
24
23
assert ( n . _color === BLACK ) ;
25
24
assert ( n . parent !== null ) ;
26
25
const s = sibling ( n ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'assert';
2
2
import BLACK from '../color/BLACK.js' ;
3
3
import RED from '../color/RED.js' ;
4
4
import Node from '../types/Node.js' ;
5
- import Leaf from '../types/Leaf.js' ;
6
5
7
6
import replace_node from './replace_node.js' ;
8
7
import delete_case2 from './delete_case2.js' ;
@@ -32,13 +31,15 @@ const delete_no_child = (n) => {
32
31
assert ( n . _color === BLACK ) ;
33
32
34
33
// Mock leaf since there is no left child
35
- const leaf = new Leaf ( null ) ;
34
+ // We use key = n.key to avoid mixing types, but this property is never
35
+ // accessed.
36
+ const leaf = new Node ( BLACK , n . key ) ;
36
37
37
38
// Replace n with the mocked leaf
38
39
replace_node ( n , leaf ) ;
39
40
40
41
// If n is black, deleting it reduces the black-height of every path going
41
- // through it by 1. Leaf is black, so there are more things to fix.
42
+ // through it by 1. The leaf is black, so there are more things to fix.
42
43
delete_case2 ( leaf ) ;
43
44
44
45
// Delete mocked leaf
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from '../types/Node.js' ;
3
- import Leaf from '../types/Leaf.js' ;
4
3
5
4
/**
6
5
* Prune subtree rooted at input node.
7
6
*
8
- * @param {Node|Leaf } root - The leaf to delete .
7
+ * @param {Node } root - The root of the subtree to prune .
9
8
*/
10
9
const prune = ( root ) => {
11
- assert ( root instanceof Node || root instanceof Leaf ) ;
10
+ assert ( root instanceof Node ) ;
12
11
assert ( root . parent !== null ) ;
13
12
14
13
if ( root === root . parent . left ) root . parent . left = null ;
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from '../types/Node.js' ;
3
- import Leaf from '../types/Leaf.js' ;
4
3
5
4
/**
6
5
* Replaces node <code>A</code> by node <code>B</code>.
7
6
*
8
7
* @param {Node } A - The node to replace.
9
- * @param {Node|Leaf } B - The replacement node.
8
+ * @param {Node } B - The replacement node.
10
9
*/
11
10
const replace_node = ( A , B ) => {
12
11
assert ( A instanceof Node ) ;
13
- assert ( B instanceof Node || B instanceof Leaf ) ;
12
+ assert ( B instanceof Node ) ;
14
13
// We never apply delete_one_child or delete_no_child on the root
15
14
assert ( A . parent !== null ) ;
16
15
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
2
import Node from '../types/Node.js' ;
3
- import Leaf from '../types/Leaf.js' ;
4
3
5
4
/**
6
5
* Computes the sibling of the input node.
7
6
*
8
- * @param {Node|Leaf } node - The input node.
7
+ * @param {Node } node - The input node.
9
8
* @returns {Node }
10
9
*/
11
10
const sibling = ( node ) => {
12
- assert ( node instanceof Node || node instanceof Leaf ) ;
11
+ assert ( node instanceof Node ) ;
13
12
// We only use this function when node HAS a non-leaf sibling.
14
13
assert ( node . parent !== null ) ;
15
14
Original file line number Diff line number Diff line change @@ -28,6 +28,5 @@ export {default as rotate_right} from './rotate/rotate_right.js';
28
28
export { default as search } from './search/search.js' ;
29
29
export { default as inordertraversal } from './traversal/inordertraversal.js' ;
30
30
export { default as rangetraversal } from './traversal/rangetraversal.js' ;
31
- export { default as Leaf } from './types/Leaf.js' ;
32
31
export { default as Node } from './types/Node.js' ;
33
32
export { default as RedBlackTree } from './types/RedBlackTree.js' ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments