File tree Expand file tree Collapse file tree 5 files changed +16
-0
lines changed Expand file tree Collapse file tree 5 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,15 @@ import insert_case2 from './insert_case2.js';
77/**
88 * Preconditions:
99 * - n is red.
10+ * - n's children are BLACK
1011 *
1112 * @param {Node } n - The input node.
1213 */
1314const insert_case1 = ( n ) => {
1415 assert ( n instanceof Node ) ;
1516 assert ( n . _color === RED ) ;
17+ assert ( n . left . _color === BLACK ) ;
18+ assert ( n . right . _color === BLACK ) ;
1619 /**
1720 * If n is the root of the tree, paint it black and we are done.
1821 *
Original file line number Diff line number Diff line change @@ -7,13 +7,16 @@ import insert_case3 from './insert_case3.js';
77/**
88 * Preconditions:
99 * - n is red.
10+ * - n's children are BLACK
1011 * - n is not the root of the tree.
1112 *
1213 * @param {Node } n - The input node.
1314 */
1415const insert_case2 = ( n ) => {
1516 assert ( n instanceof Node ) ;
1617 assert ( n . _color === RED ) ;
18+ assert ( n . left . _color === BLACK ) ;
19+ assert ( n . right . _color === BLACK ) ;
1720 assert ( n . parent !== null ) ;
1821
1922 /**
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import insert_case4 from './insert_case4.js';
1010/**
1111 * Preconditions:
1212 * - n is red.
13+ * - n's children are BLACK
1314 * - n is not the root of the tree.
1415 * - n's parent is red.
1516 *
@@ -18,6 +19,8 @@ import insert_case4 from './insert_case4.js';
1819const insert_case3 = ( n ) => {
1920 assert ( n instanceof Node ) ;
2021 assert ( n . _color === RED ) ;
22+ assert ( n . left . _color === BLACK ) ;
23+ assert ( n . right . _color === BLACK ) ;
2124 assert ( n . parent !== null ) ;
2225 assert ( n . parent . _color === RED ) ;
2326 const u = uncle ( n ) ;
Original file line number Diff line number Diff line change 11import assert from 'assert' ;
22import Node from '../adt/Node.js' ;
3+ import BLACK from '../color/BLACK.js' ;
34import RED from '../color/RED.js' ;
45import rotate_left from '../rotate/rotate_left.js' ;
56import rotate_right from '../rotate/rotate_right.js' ;
@@ -9,6 +10,7 @@ import insert_case5 from './insert_case5.js';
910/**
1011 * Preconditions:
1112 * - n is red.
13+ * - n's children are BLACK
1214 * - n is not the root of the tree.
1315 * - n's parent is red.
1416 * - n's uncle is black.
@@ -20,6 +22,8 @@ import insert_case5 from './insert_case5.js';
2022const insert_case4 = ( n ) => {
2123 assert ( n instanceof Node ) ;
2224 assert ( n . _color === RED ) ;
25+ assert ( n . left . _color === BLACK ) ;
26+ assert ( n . right . _color === BLACK ) ;
2327 assert ( n . parent !== null ) ;
2428 assert ( n . parent . _color === RED ) ;
2529 const g = grandparent ( n ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import grandparent from '../family/grandparent.js';
99/**
1010 * Preconditions:
1111 * - n is red.
12+ * - n's children are BLACK
1213 * - n is not the root of the tree.
1314 * - n's parent is red.
1415 * - n's uncle is black.
@@ -19,6 +20,8 @@ import grandparent from '../family/grandparent.js';
1920const insert_case5 = ( n ) => {
2021 assert ( n instanceof Node ) ;
2122 assert ( n . _color === RED ) ;
23+ assert ( n . left . _color === BLACK ) ;
24+ assert ( n . right . _color === BLACK ) ;
2225 assert ( n . parent !== null ) ;
2326 assert ( n . parent . _color === RED ) ;
2427 const g = grandparent ( n ) ;
You can’t perform that action at this time.
0 commit comments