Skip to content

Commit 8bd4b37

Browse files
♻️ refactor: Use arrow functions where possible.
1 parent 586ce4e commit 8bd4b37

21 files changed

+42
-42
lines changed

src/deletion/delete_case1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {delete_case2} from './delete_case2.js';
88
*
99
* @param {Node} n - The input node.
1010
*/
11-
export function delete_case1(n) {
11+
export const delete_case1 = (n) => {
1212
// If n is the root, there is nothing to do: all paths go through n, and n
1313
// is black.
1414
if (n.parent !== null) delete_case2(n);
15-
}
15+
};

src/deletion/delete_case2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {delete_case4} from './delete_case4.js';
1414
*
1515
* @param {Node} n - The input node.
1616
*/
17-
export function delete_case2(n) {
17+
export const delete_case2 = (n) => {
1818
const s = sibling(n);
1919

2020
/**
@@ -38,4 +38,4 @@ export function delete_case2(n) {
3838

3939
// Otherwise, go to case 3.
4040
else delete_case3(n);
41-
}
41+
};

src/deletion/delete_case3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {delete_case4} from './delete_case4.js';
1414
*
1515
* @param {Node} n - The input node.
1616
*/
17-
export function delete_case3(n) {
17+
export const delete_case3 = (n) => {
1818
const s = sibling(n);
1919

2020
/**
@@ -41,4 +41,4 @@ export function delete_case3(n) {
4141

4242
// Otherwise, go to case 4.
4343
else delete_case4(n);
44-
}
44+
};

src/deletion/delete_case4.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {delete_case5} from './delete_case5.js';
1414
*
1515
* @param {Node} n - The input node.
1616
*/
17-
export function delete_case4(n) {
17+
export const delete_case4 = (n) => {
1818
const s = sibling(n);
1919

2020
/**
@@ -43,4 +43,4 @@ export function delete_case4(n) {
4343

4444
// Otherwise, go to case 5.
4545
else delete_case5(n);
46-
}
46+
};

src/deletion/delete_case5.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {delete_case6} from './delete_case6.js';
1515
*
1616
* @param {Node} n - The input node.
1717
*/
18-
export function delete_case5(n) {
18+
export const delete_case5 = (n) => {
1919
const s = sibling(n);
2020

2121
// The following statements just force the red n's sibling child to be on
@@ -55,4 +55,4 @@ export function delete_case5(n) {
5555
}
5656

5757
delete_case6(n);
58-
}
58+
};

src/deletion/delete_case6.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {sibling} from '../family/sibling.js';
1414
*
1515
* @param {Node} n - The input node.
1616
*/
17-
export function delete_case6(n) {
17+
export const delete_case6 = (n) => {
1818
const s = sibling(n);
1919

2020
/**
@@ -48,4 +48,4 @@ export function delete_case6(n) {
4848
s.left.color = BLACK;
4949
rotate_right(n.parent);
5050
}
51-
}
51+
};

src/deletion/delete_one_child.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {delete_case1} from './delete_case1.js';
1212
*
1313
* @param {Node} n - The node to delete.
1414
*/
15-
export function delete_one_child(n) {
15+
export const delete_one_child = (n) => {
1616
// Precondition: n has at most one non-leaf child.
1717
// assert( n.right.isLeaf() || n.left.isLeaf());
1818

@@ -39,4 +39,4 @@ export function delete_one_child(n) {
3939
// If n is red then its child can only be black. Replacing n with its
4040
// child suffices.
4141
// }
42-
}
42+
};

src/deletion/replace_node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* @param {Node} A - The node to replace.
55
* @param {Node} B - The replacement node.
66
*/
7-
export function replace_node(A, B) {
7+
export const replace_node = (A, B) => {
88
// Assert( A.parent !== null ) ;
99
// we never apply delete_one_child on the root so we are safe
1010

1111
if (A === A.parent.left) A.parent.left = B;
1212
else A.parent.right = B;
1313

1414
B.parent = A.parent;
15-
}
15+
};

src/family/grandparent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @param {Node} node - The input node.
55
* @returns {Node}
66
*/
7-
export function grandparent(node) {
7+
export const grandparent = (node) => {
88
// Assert((node !== null) && (node.parent !== null));
99
// We only call this function when node HAS a grandparent
1010
return node.parent.parent;
11-
}
11+
};

src/family/predecessor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* @param {Node} node - The input node.
66
* @returns {Node}
77
*/
8-
export function predecessor(node) {
8+
export const predecessor = (node) => {
99
// Assert( !node.left.isLeaf() ) ;
1010
let pred = node.left;
1111

1212
while (!pred.right.isLeaf()) pred = pred.right;
1313

1414
return pred;
15-
}
15+
};

src/family/sibling.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* @param {Node} node - The input node.
55
* @returns {Node}
66
*/
7-
export function sibling(node) {
7+
export const sibling = (node) => {
88
// Assert((node !== null) && (node.parent !== null));
99
// We only use this function when node HAS a sibling so this case can never
1010
// happen.
1111

1212
return node === node.parent.left ? node.parent.right : node.parent.left;
13-
}
13+
};

src/family/uncle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {grandparent} from './grandparent.js';
77
* @param {Node} node - The input node.
88
* @returns {Node}
99
*/
10-
export function uncle(node) {
10+
export const uncle = (node) => {
1111
const g = grandparent(node);
1212
// Assert( g !== null ) ;
1313
// this can never happen
1414
if (node.parent === g.left) return g.right.isLeaf() ? null : g.right;
1515
return g.left.isLeaf() ? null : g.left;
16-
}
16+
};

src/insertion/insert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @param {Node} B - The node to insert.
1515
* @returns {Node} B - The node that has been inserted.
1616
*/
17-
export function insert(compare, A, B) {
17+
export const insert = (compare, A, B) => {
1818
while (true) {
1919
if (compare(B.key, A.key) < 0) {
2020
const node = A.left;
@@ -40,4 +40,4 @@ export function insert(compare, A, B) {
4040
B.parent = A;
4141

4242
return B;
43-
}
43+
};

src/insertion/insert_case1.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {insert_case2} from './insert_case2.js';
77
*
88
* @param {Node} n - The input node.
99
*/
10-
export function insert_case1(n) {
10+
export const insert_case1 = (n) => {
1111
/**
1212
* If n is the root of the tree, paint it black and we are done.
1313
*
@@ -17,4 +17,4 @@ export function insert_case1(n) {
1717
*/
1818
if (n.parent === null) n.color = BLACK;
1919
else insert_case2(n);
20-
}
20+
};

src/insertion/insert_case2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {insert_case3} from './insert_case3.js';
88
*
99
* @param {Node} n - The input node.
1010
*/
11-
export function insert_case2(n) {
11+
export const insert_case2 = (n) => {
1212
/**
1313
* If the parent of n is black then we have nothing to do.
1414
*
@@ -21,4 +21,4 @@ export function insert_case2(n) {
2121
if (n.parent.color === BLACK) return;
2222

2323
insert_case3(n);
24-
}
24+
};

src/insertion/insert_case3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {insert_case4} from './insert_case4.js';
1111
*
1212
* @param {Node} n - The input node.
1313
*/
14-
export function insert_case3(n) {
14+
export const insert_case3 = (n) => {
1515
const u = uncle(n);
1616

1717
/**
@@ -35,4 +35,4 @@ export function insert_case3(n) {
3535
g.color = RED;
3636
insert_case1(g);
3737
} else insert_case4(n);
38-
}
38+
};

src/insertion/insert_case4.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {insert_case5} from './insert_case5.js';
1313
*
1414
* @param {Node} n - The input node.
1515
*/
16-
export function insert_case4(n) {
16+
export const insert_case4 = (n) => {
1717
const g = grandparent(n);
1818

1919
/**
@@ -75,4 +75,4 @@ export function insert_case4(n) {
7575
}
7676

7777
insert_case5(n);
78-
}
78+
};

src/insertion/insert_case5.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {grandparent} from '../family/grandparent.js';
1212
*
1313
* @param {Node} n - The input node.
1414
*/
15-
export function insert_case5(n) {
15+
export const insert_case5 = (n) => {
1616
const g = grandparent(n);
1717

1818
// Repaint n's parent black, n's grandparent red
@@ -44,4 +44,4 @@ export function insert_case5(n) {
4444
* / \ / \
4545
* = = - -
4646
*/ else rotate_left(g);
47-
}
47+
};

src/rotate/rotate_left.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

16-
export function rotate_left(A) {
16+
export const rotate_left = (A) => {
1717
const B = A.right;
1818
const a = A.left;
1919
const b = B.left;
@@ -31,4 +31,4 @@ export function rotate_left(A) {
3131
a.parent = B;
3232
b.parent = B;
3333
c.parent = A;
34-
}
34+
};

src/rotate/rotate_right.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

16-
export function rotate_right(B) {
16+
export const rotate_right = (B) => {
1717
const A = B.left;
1818
const a = A.left;
1919
const b = A.right;
@@ -31,4 +31,4 @@ export function rotate_right(B) {
3131
a.parent = B;
3232
b.parent = A;
3333
c.parent = A;
34-
}
34+
};

src/search/search.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param {Key} key - The key to search for.
77
* @returns {Node}
88
*/
9-
export function search(compare, root, key) {
9+
export const search = (compare, root, key) => {
1010
while (true) {
1111
const d = compare(key, root.key);
1212

@@ -20,4 +20,4 @@ export function search(compare, root, key) {
2020
return null;
2121
}
2222
}
23-
}
23+
};

0 commit comments

Comments
 (0)