Skip to content

Commit bfedb15

Browse files
💥 refactor!: Rename isleaf to isLeaf.
BREAKING CHANGE: This breaks dependents relying on this method.
1 parent d81747d commit bfedb15

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

src/adt/Leaf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export function Leaf(parent) {
1818
*
1919
* @returns {Boolean}
2020
*/
21-
Leaf.prototype.isleaf = function () {
21+
Leaf.prototype.isLeaf = function () {
2222
return true;
2323
};

src/adt/Node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export function Node(color, key) {
2222
*
2323
* @returns {Boolean}
2424
*/
25-
Node.prototype.isleaf = function () {
25+
Node.prototype.isLeaf = function () {
2626
return false;
2727
};

src/adt/RedBlackTree.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export class RedBlackTree {
8080
* @param {Node} node - The input node to delete.
8181
*/
8282
_delete(node) {
83-
if (!node.left.isleaf()) {
83+
if (!node.left.isLeaf()) {
8484
// Replace node's key with predecessor's key
8585
const pred = predecessor(node);
8686
node.key = pred.key;
8787
// Delete predecessor node
8888
// note: this node can only have one non-leaf child
8989
// because the tree is a red-black tree
9090
delete_one_child(pred);
91-
} else if (!node.right.isleaf()) {
91+
} else if (!node.right.isLeaf()) {
9292
// Replace node's key with successor's key
9393
// If there is no left child, then there can only be one right
9494
// child.

src/debug/debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {BLACK} from '../color/BLACK.js';
99
*/
1010
export function _debug({red, black}) {
1111
const debug = (root) => {
12-
if (root.isleaf()) return black('L');
12+
if (root.isLeaf()) return black('L');
1313

1414
const repr = root.color === BLACK ? black(root.key) : red(root.key);
1515

src/deletion/delete_one_child.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {delete_case1} from './delete_case1.js';
1414
*/
1515
export function delete_one_child(n) {
1616
// Precondition: n has at most one non-leaf child.
17-
// assert( n.right.isleaf() || n.left.isleaf());
17+
// assert( n.right.isLeaf() || n.left.isLeaf());
1818

19-
// const child = n.right.isleaf() ? n.left : n.right;
19+
// const child = n.right.isLeaf() ? n.left : n.right;
2020
// n.right is always a LEAF because either n is a subtree predecessor or it
2121
// is the only child of its parent by the red-black tree properties
2222
const child = n.left;

src/family/predecessor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* @returns {Node}
77
*/
88
export function predecessor(node) {
9-
// Assert( !node.left.isleaf() ) ;
9+
// Assert( !node.left.isLeaf() ) ;
1010
let pred = node.left;
1111

12-
while (!pred.right.isleaf()) pred = pred.right;
12+
while (!pred.right.isLeaf()) pred = pred.right;
1313

1414
return pred;
1515
}

src/family/uncle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export function uncle(node) {
1111
const g = grandparent(node);
1212
// Assert( g !== null ) ;
1313
// this can never happen
14-
if (node.parent === g.left) return g.right.isleaf() ? null : g.right;
15-
return g.left.isleaf() ? null : g.left;
14+
if (node.parent === g.left) return g.right.isLeaf() ? null : g.right;
15+
return g.left.isLeaf() ? null : g.left;
1616
}

src/insertion/insert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function insert(compare, A, B) {
1919
if (compare(B.key, A.key) < 0) {
2020
const node = A.left;
2121

22-
if (node.isleaf()) {
22+
if (node.isLeaf()) {
2323
A.left = B;
2424
break;
2525
}
@@ -28,7 +28,7 @@ export function insert(compare, A, B) {
2828
} else {
2929
const node = A.right;
3030

31-
if (node.isleaf()) {
31+
if (node.isLeaf()) {
3232
A.right = B;
3333
break;
3434
}

src/search/search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function search(compare, root, key) {
1616

1717
root = d < 0 ? root.left : root.right;
1818

19-
if (root.isleaf()) {
19+
if (root.isLeaf()) {
2020
return null;
2121
}
2222
}

src/traversal/inordertraversal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @returns {Iterator}
66
*/
77
export function* inordertraversal(node) {
8-
if (!node.left.isleaf()) {
8+
if (!node.left.isLeaf()) {
99
// Yield the nodes on the left recursively. Those nodes are all smaller
1010
// than (or equal to) the current node by the binary search tree
1111
// properties.
@@ -15,7 +15,7 @@ export function* inordertraversal(node) {
1515
// Yield the current node.
1616
yield node.key;
1717

18-
if (!node.right.isleaf()) {
18+
if (!node.right.isLeaf()) {
1919
// Yield the nodes on the right recursively. Those nodes are all larger
2020
// than (or equal to) the current node by the binary search tree
2121
// properties.

src/traversal/rangetraversal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ export function* rangetraversal(compare, root, left, right) {
1212
if (compare(root.key, left) < 0) {
1313
// If the root lies to the left of the interval, we can discard the
1414
// entire left subtree.
15-
if (!root.right.isleaf())
15+
if (!root.right.isLeaf())
1616
yield* rangetraversal(compare, root.right, left, right);
1717
} else if (compare(root.key, right) >= 0) {
1818
// If the root lies to the right of the interval, we can discard the
1919
// entire right subtree.
20-
if (!root.left.isleaf())
20+
if (!root.left.isLeaf())
2121
yield* rangetraversal(compare, root.left, left, right);
2222
} else {
2323
// Otherwise just recurse on both subtrees and yield the root in
2424
// between.
25-
if (!root.left.isleaf())
25+
if (!root.left.isLeaf())
2626
yield* rangetraversal(compare, root.left, left, right);
2727
yield root.key;
28-
if (!root.right.isleaf())
28+
if (!root.right.isLeaf())
2929
yield* rangetraversal(compare, root.right, left, right);
3030
}
3131
}

0 commit comments

Comments
 (0)