Added Missing method & fixed potential issue with TreeSetBiIterators

This commit is contained in:
Speiger 2021-12-13 13:56:28 +01:00
parent 18f6704ed7
commit 59a417056c
4 changed files with 36 additions and 8 deletions

View File

@ -650,7 +650,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
}
protected BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element) {
return null;
return new AscendingKeyIterator(findNode(element));
}
protected BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator() {

View File

@ -650,7 +650,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
}
protected BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element) {
return null;
return new AscendingKeyIterator(findNode(element));
}
protected BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator() {

View File

@ -1280,6 +1280,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
boolean unboundForwardFence;
boolean unboundBackwardFence;
KEY_TYPE forwardFence;
@ -1305,6 +1306,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@ -1319,13 +1321,14 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(lastReturned.needsSuccessor()) next = lastReturned;
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
set.removeNode(lastReturned);
lastReturned = null;
}
@ -1335,6 +1338,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
boolean unboundForwardFence;
boolean unboundBackwardFence;
KEY_TYPE forwardFence;
@ -1360,6 +1364,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@ -1374,12 +1379,14 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
set.removeNode(lastReturned);
lastReturned = null;
}
@ -1390,6 +1397,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
{
@ -1407,6 +1415,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@ -1421,13 +1430,14 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(lastReturned.needsSuccessor()) next = lastReturned;
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
removeNode(lastReturned);
lastReturned = null;
}
@ -1437,7 +1447,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
{
next = first;
@ -1454,6 +1465,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@ -1468,12 +1480,14 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
removeNode(lastReturned);
lastReturned = null;
}

View File

@ -1341,6 +1341,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
boolean unboundForwardFence;
boolean unboundBackwardFence;
KEY_TYPE forwardFence;
@ -1366,6 +1367,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@ -1380,13 +1382,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(lastReturned.needsSuccessor()) next = lastReturned;
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
set.removeNode(lastReturned);
lastReturned = null;
}
@ -1396,6 +1399,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
boolean unboundForwardFence;
boolean unboundBackwardFence;
KEY_TYPE forwardFence;
@ -1421,6 +1425,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@ -1435,12 +1440,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
set.removeNode(lastReturned);
lastReturned = null;
}
@ -1451,6 +1458,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
{
@ -1468,6 +1476,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@ -1482,13 +1491,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(lastReturned.needsSuccessor()) next = lastReturned;
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
removeNode(lastReturned);
lastReturned = null;
}
@ -1498,7 +1508,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
{
Entry KEY_GENERIC_TYPE lastReturned;
Entry KEY_GENERIC_TYPE next;
boolean forwards = false;
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
{
next = first;
@ -1515,6 +1526,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.previous();
forwards = false;
return result;
}
@ -1529,12 +1541,14 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
lastReturned = next;
KEY_TYPE result = next.key;
next = next.next();
forwards = true;
return result;
}
@Override
public void remove() {
if(lastReturned == null) throw new IllegalStateException();
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
removeNode(lastReturned);
lastReturned = null;
}