Skip to content

Commit 6798cbd

Browse files
💥 feat(RedBlackTree#get)!: Return undefined when key is missing.
Fixes #109. BREAKING CHANGE: This breaks dependents relying on #get returning null.
1 parent 3a6f20d commit 6798cbd

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: src/types/RedBlackTree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class RedBlackTree {
8989
*/
9090
get(key) {
9191
const node = this._search(key);
92-
return node === null ? null : node.key;
92+
return node === null ? undefined : node.key;
9393
}
9494

9595
/**

Diff for: test/src/RedBlackTree/get.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for (const compare of [increasing, decreasing]) {
1010
test(`RedBlackTree::get [${compare.name}]`, (t) => {
1111
const tree = RedBlackTree.empty(compare);
1212

13-
t.is(tree.get(0), null);
13+
t.true(tree.get(0) === undefined);
1414

1515
const n = 10000;
1616
const reference = [];
@@ -26,7 +26,7 @@ for (const compare of [increasing, decreasing]) {
2626
t.deepEqual(tree.get(x), x);
2727
}
2828

29-
t.is(tree.get(-1), null);
30-
t.is(tree.get(n), null);
29+
t.true(tree.get(-1) === undefined);
30+
t.true(tree.get(n) === undefined);
3131
});
3232
}

Diff for: test/src/RedBlackTree/remove.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const macro = (t, reference) => {
2828
for (const i of range(m)) {
2929
const x = reference[i];
3030
t.true(tree.remove(x));
31-
t.true(tree.get(x) === null);
31+
t.true(tree.get(x) === undefined);
3232
}
3333

3434
const _rest = iter(reference);
@@ -46,7 +46,7 @@ const macro = (t, reference) => {
4646

4747
for (const i of range(m)) {
4848
const x = reference[i];
49-
t.true(tree.get(x) === null);
49+
t.true(tree.get(x) === undefined);
5050
tree.add(x);
5151
t.true(tree.get(x) === x);
5252
}
@@ -60,7 +60,7 @@ const macro = (t, reference) => {
6060
for (const i of range(n)) {
6161
const x = reference[i];
6262
t.true(tree.remove(x));
63-
t.true(tree.get(x) === null);
63+
t.true(tree.get(x) === undefined);
6464
}
6565

6666
t.deepEqual(list(tree), [], 'tree is empty');

0 commit comments

Comments
 (0)