Fixing TreeSet Removal Bugs

-Fixed: RB&AVL TreeSet Removal & Higher Bugs.
-Fixed: Paths thanks to OvermindDL1
-Removed: JavaTests Class that was testing for finding the bugs.
This commit is contained in:
Speiger 2021-01-09 18:27:44 +01:00
parent c0c719f2b6
commit e3bcf83887
4 changed files with 56 additions and 81 deletions

View File

@ -22,7 +22,7 @@ public class TestBuilder extends TemplateProcessor
public TestBuilder()
{
super(Paths.get("src\\main\\resources\\speiger\\assets\\collections\\templates\\"), Paths.get("src\\main\\java\\speiger\\src\\collections\\"), Paths.get("src\\main\\resources\\speiger\\assets\\collections\\"));
super(Paths.get("src/main/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/main/resources/speiger/assets/collections/"));
}
@Override

View File

@ -225,6 +225,32 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
protected Entry KEY_GENERIC_TYPE findCeilingNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
int compare;
while(entry != null) {
if((compare = compare(e, entry.key)) < 0) {
if(entry.left == null) break;
entry = entry.left;
continue;
}
else if(compare > 0) {
if(entry.right != null) entry = entry.right;
else {
Entry KEY_GENERIC_TYPE parent = entry.parent;
while(parent != null && parent.right == entry) {
entry = parent;
parent = parent.parent;
}
return parent;
}
continue;
}
break;
}
return entry;
}
protected Entry KEY_GENERIC_TYPE findHigherNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
while(entry != null) {
if(compare(e, entry.key) < 0) {
@ -246,32 +272,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return null;
}
protected Entry KEY_GENERIC_TYPE findHigherNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
int compare;
while(entry != null) {
if((compare = compare(e, entry.key)) < 0) {
if(entry.left == null) break;
entry = entry.left;
continue;
}
else if(compare < 0) {
if(entry.right != null) entry = entry.right;
else {
Entry KEY_GENERIC_TYPE parent = entry.parent;
while(parent != null && parent.right == entry) {
entry = parent;
parent = parent.parent;
}
return parent;
}
continue;
}
break;
}
return entry;
}
#if !TYPE_OBJECT
@Override
public boolean contains(KEY_TYPE e) {

View File

@ -225,6 +225,32 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
}
protected Entry KEY_GENERIC_TYPE findCeilingNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
int compare;
while(entry != null) {
if((compare = compare(e, entry.key)) < 0) {
if(entry.left == null) break;
entry = entry.left;
continue;
}
else if(compare > 0) {
if(entry.right != null) entry = entry.right;
else {
Entry KEY_GENERIC_TYPE parent = entry.parent;
while(parent != null && parent.right == entry) {
entry = parent;
parent = parent.parent;
}
return parent;
}
continue;
}
break;
}
return entry;
}
protected Entry KEY_GENERIC_TYPE findHigherNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
while(entry != null) {
if(compare(e, entry.key) < 0) {
@ -246,31 +272,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
return null;
}
protected Entry KEY_GENERIC_TYPE findHigherNode(KEY_TYPE e) {
Entry KEY_GENERIC_TYPE entry = tree;
int compare;
while(entry != null) {
if((compare = compare(e, entry.key)) < 0) {
if(entry.left == null) break;
entry = entry.left;
continue;
}
else if(compare < 0) {
if(entry.right != null) entry = entry.right;
else {
Entry KEY_GENERIC_TYPE parent = entry.parent;
while(parent != null && parent.right == entry) {
entry = parent;
parent = parent.parent;
}
return parent;
}
continue;
}
break;
}
return entry;
}
#if !TYPE_OBJECT
@Override
@ -934,6 +936,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
if(current == previous) index--;
updateNext();
updatePrevious();
if(current.needsSuccessor()) next = current;
set.removeNode(current);
current = null;
}
@ -1015,6 +1018,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
if(current == previous) index--;
updateNext();
updatePrevious();
if(current.needsSuccessor()) next = current;
removeNode(current);
current = null;
}

View File

@ -1,29 +0,0 @@
package speiger.src.collections.ints.utils;
import java.util.Arrays;
import java.util.TreeSet;
import java.util.stream.IntStream;
import org.junit.Assert;
import org.junit.Test;
public class JavaTests
{
protected static final Integer[] CONTAINS_ARRAY = new Integer[]{23, 45, 63, 89, 32};
protected static final Integer[] TEST_ARRAY = IntStream.range(0, 100).mapToObj(Integer::valueOf).toArray(Integer[]::new);
private TreeSet<Integer> create(Integer[] array)
{
TreeSet<Integer> tree = new TreeSet<Integer>();
tree.addAll(Arrays.asList(array));
return tree;
}
@Test
public void simpleTest()
{
TreeSet<Integer> collection = create(TEST_ARRAY);
Assert.assertTrue(collection.removeAll(create(CONTAINS_ARRAY)));
Assert.assertFalse(collection.removeAll(create(CONTAINS_ARRAY)));
}
}