Skip to content

Commit

Permalink
fix for replacing single-char-node with value with array-node
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzardo committed Nov 13, 2023
1 parent dcc072c commit f7a4421
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public CharTreeNode<V> append(char b) {
if (next != null && this.b != b) {
ArrayCharTreeNode<V> node = new ArrayCharTreeNode<V>(Math.max(this.b, b));
node.set(this.b, next);
node.value = value;
node.append(b);
return node;
} else if (this.b == b)
Expand All @@ -287,6 +288,7 @@ public CharTreeNode<V> set(char b, CharTreeNode<V> n) {
if (next != null && this.b != b) {
ArrayCharTreeNode<V> node = new ArrayCharTreeNode<V>(Math.max(this.b, b));
node.set(this.b, next);
node.value = value;
node.set(b, n);
return node;
} else if (this.b == b) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/wizzardo/tools/misc/CharTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public void test2() {
.append("foo", "foo")
.append("bar", "bar")
.append("foobar", "foobar")
.append("foo", "foo");
.append("foo2bar", "foo2bar");

Assert.assertEquals("foo", tree.get("foo".toCharArray()));
Assert.assertEquals("bar", tree.get("bar".toCharArray()));
Assert.assertEquals("foobar", tree.get("foobar".toCharArray()));
Assert.assertEquals("foo2bar", tree.get("foo2bar".toCharArray()));
}

@Test
Expand Down

0 comments on commit f7a4421

Please sign in to comment.