Skip to content

Commit 2967f9c

Browse files
💥 refactor!: Rename color property to _color.
This is to allow for mangling since color is a DOM API prop. BREAKING CHANGE: This breaks dependencies on this property.
1 parent 8bd4b37 commit 2967f9c

15 files changed

+37
-37
lines changed

src/adt/Leaf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {BLACK} from '../color/BLACK.js';
88
* @returns {Leaf}
99
*/
1010
export function Leaf(parent) {
11-
this.color = BLACK;
11+
this._color = BLACK;
1212
this.parent = parent;
1313
}
1414

src/adt/Node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {Leaf} from './Leaf.js';
99
* @returns {Node}
1010
*/
1111
export function Node(color, key) {
12-
this.color = color;
12+
this._color = color;
1313
this.left = new Leaf(this);
1414
this.right = new Leaf(this);
1515
this.parent = null;

src/debug/debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const _debug = ({red, black}) => {
1717
const debug = (root) => {
1818
if (root.isLeaf()) return black('L');
1919

20-
const repr = root.color === BLACK ? black(root.key) : red(root.key);
20+
const repr = root._color === BLACK ? black(root.key) : red(root.key);
2121

2222
return `(${debug(root.left)}, ${repr}, ${debug(root.right)})`;
2323
};

src/deletion/delete_case2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export const delete_case2 = (n) => {
2828
* / \ / \ / \ / \
2929
* = = = = - - = =
3030
*/
31-
if (s.color === RED) {
32-
n.parent.color = RED;
33-
s.color = BLACK;
31+
if (s._color === RED) {
32+
n.parent._color = RED;
33+
s._color = BLACK;
3434
if (n === n.parent.left) rotate_left(n.parent);
3535
else rotate_right(n.parent);
3636
delete_case4(n);

src/deletion/delete_case3.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export const delete_case3 = (n) => {
3131
* - - - - - - - -
3232
*/
3333
if (
34-
n.parent.color === BLACK &&
35-
s.left.color === BLACK &&
36-
s.right.color === BLACK
34+
n.parent._color === BLACK &&
35+
s.left._color === BLACK &&
36+
s.right._color === BLACK
3737
) {
38-
s.color = RED;
38+
s._color = RED;
3939
delete_case1(n.parent);
4040
}
4141

src/deletion/delete_case4.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export const delete_case4 = (n) => {
3333
*/
3434
if (
3535
// The parent color test is always true when coming from case 2
36-
n.parent.color === RED &&
37-
s.left.color === BLACK &&
38-
s.right.color === BLACK
36+
n.parent._color === RED &&
37+
s.left._color === BLACK &&
38+
s.right._color === BLACK
3939
) {
40-
s.color = RED;
41-
n.parent.color = BLACK;
40+
s._color = RED;
41+
n.parent._color = BLACK;
4242
}
4343

4444
// Otherwise, go to case 5.

src/deletion/delete_case5.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export const delete_case5 = (n) => {
3333
* / \
3434
* - -
3535
*/
36-
if (n === n.parent.left && s.right.color === BLACK) {
37-
s.color = RED;
38-
s.left.color = BLACK;
36+
if (n === n.parent.left && s.right._color === BLACK) {
37+
s._color = RED;
38+
s.left._color = BLACK;
3939
rotate_right(s);
40-
} else if (n === n.parent.right && s.left.color === BLACK) {
40+
} else if (n === n.parent.right && s.left._color === BLACK) {
4141
/**
4242
* ? ?
4343
* / \ / \
@@ -49,8 +49,8 @@ export const delete_case5 = (n) => {
4949
* / \
5050
* - -
5151
*/
52-
s.color = RED;
53-
s.right.color = BLACK;
52+
s._color = RED;
53+
s.right._color = BLACK;
5454
rotate_left(s);
5555
}
5656

src/deletion/delete_case6.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ export const delete_case6 = (n) => {
3535
* - -
3636
*/
3737

38-
s.color = n.parent.color;
39-
n.parent.color = BLACK;
38+
s._color = n.parent._color;
39+
n.parent._color = BLACK;
4040

4141
if (n === n.parent.left) {
42-
s.right.color = BLACK;
42+
s.right._color = BLACK;
4343
rotate_left(n.parent);
4444
}
4545

4646
// Symmetric case
4747
else {
48-
s.left.color = BLACK;
48+
s.left._color = BLACK;
4949
rotate_right(n.parent);
5050
}
5151
};

src/deletion/delete_one_child.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export const delete_one_child = (n) => {
2626

2727
// If n is black, deleting it reduces the black-height of every path going
2828
// through it by 1.
29-
if (n.color === BLACK) {
29+
if (n._color === BLACK) {
3030
// We can easily fix this when its left child is an
3131
// internal red node: change the color of the left child to black and
3232
// replace n with it.
33-
if (child.color === RED) child.color = BLACK;
33+
if (child._color === RED) child._color = BLACK;
3434
// Otherwise, there are more things to fix.
3535
else delete_case1(child);
3636
}

src/insertion/insert_case1.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export const insert_case1 = (n) => {
1515
* / \
1616
* - -
1717
*/
18-
if (n.parent === null) n.color = BLACK;
18+
if (n.parent === null) n._color = BLACK;
1919
else insert_case2(n);
2020
};

src/insertion/insert_case2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const insert_case2 = (n) => {
1818
* / \
1919
* - -
2020
*/
21-
if (n.parent.color === BLACK) return;
21+
if (n.parent._color === BLACK) return;
2222

2323
insert_case3(n);
2424
};

src/insertion/insert_case3.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export const insert_case3 = (n) => {
2828
* - - - -
2929
*/
3030

31-
if (u !== null && u.color === RED) {
32-
n.parent.color = BLACK;
33-
u.color = BLACK;
31+
if (u !== null && u._color === RED) {
32+
n.parent._color = BLACK;
33+
u._color = BLACK;
3434
const g = grandparent(n);
35-
g.color = RED;
35+
g._color = RED;
3636
insert_case1(g);
3737
} else insert_case4(n);
3838
};

src/insertion/insert_case5.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const insert_case5 = (n) => {
1616
const g = grandparent(n);
1717

1818
// Repaint n's parent black, n's grandparent red
19-
n.parent.color = BLACK;
20-
g.color = RED;
19+
n.parent._color = BLACK;
20+
g._color = RED;
2121

2222
/**
2323
* If the path from g to n makes a left-left, {@link rotate_right} at g.

src/rotate/rotate_left.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const rotate_left = (A) => {
2020
const c = B.right;
2121

2222
[A.key, B.key] = [B.key, A.key];
23-
[A.color, B.color] = [B.color, A.color];
23+
[A._color, B._color] = [B._color, A._color];
2424

2525
A.left = B;
2626
A.right = c;

src/rotate/rotate_right.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const rotate_right = (B) => {
2020
const c = B.right;
2121

2222
[A.key, B.key] = [B.key, A.key];
23-
[A.color, B.color] = [B.color, A.color];
23+
[A._color, B._color] = [B._color, A._color];
2424

2525
B.left = a;
2626
B.right = A;

0 commit comments

Comments
 (0)