|
|
@@ -31,7 +31,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
/**
|
|
|
* A reference end the root entry.
|
|
|
*/
|
|
|
- protected transient Entry<K> tree;
|
|
|
+ protected transient Node<K> tree;
|
|
|
/**
|
|
|
* Number of elements in this set.
|
|
|
*/
|
|
|
@@ -39,11 +39,11 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
/**
|
|
|
* The entry of the first element of this set.
|
|
|
*/
|
|
|
- protected transient Entry<K> firstEntry;
|
|
|
+ protected transient Node<K> firstEntry;
|
|
|
/**
|
|
|
* The entry of the last element of this set.
|
|
|
*/
|
|
|
- protected transient Entry<K> lastEntry;
|
|
|
+ protected transient Node<K> lastEntry;
|
|
|
|
|
|
/**
|
|
|
* This vector remembers the path and the direction followed during the
|
|
|
@@ -51,7 +51,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*/
|
|
|
protected transient boolean dirPath[];
|
|
|
|
|
|
- protected transient Entry<K> nodePath[];
|
|
|
+ protected transient Node<K> nodePath[];
|
|
|
|
|
|
/**
|
|
|
* Creates a new empty tree set.
|
|
|
@@ -162,6 +162,12 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
add(values[ i]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private void allocatePaths() {
|
|
|
+ dirPath = new boolean[64];
|
|
|
+ nodePath = new Node[64];
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Returns the entry corresponding end the given key, if it is in the tree;
|
|
|
@@ -171,8 +177,8 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the corresponding entry, or <code>null</code> if no entry with
|
|
|
* the given key exists.
|
|
|
*/
|
|
|
- final Entry<K> findKey(K key) {
|
|
|
- Entry<K> entry = tree;
|
|
|
+ final Node<K> findNode(K key) {
|
|
|
+ Node<K> entry = tree;
|
|
|
int cmp;
|
|
|
while (entry != null && (cmp = compare(key, entry.key)) != 0) {
|
|
|
entry = cmp < 0 ? entry.left() : entry.right();
|
|
|
@@ -188,8 +194,8 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* given key, if it present; otherwise, it will be either the smallest
|
|
|
* greater key or the greatest smaller key.
|
|
|
*/
|
|
|
- final Entry<K> locateKey(K key) {
|
|
|
- Entry<K> entry = tree, last = tree;
|
|
|
+ final Node<K> locateNode(K key) {
|
|
|
+ Node<K> entry = tree, last = tree;
|
|
|
int cmp = 0;
|
|
|
while (entry != null && (cmp = compare(key, entry.key)) != 0) {
|
|
|
last = entry;
|
|
|
@@ -198,21 +204,15 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
return cmp == 0 ? entry : last;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private void allocatePaths() {
|
|
|
- dirPath = new boolean[64];
|
|
|
- nodePath = new Entry[64];
|
|
|
- }
|
|
|
-
|
|
|
@SuppressWarnings("PMD")
|
|
|
@Override
|
|
|
public final boolean add(K value) {
|
|
|
int maxDepth = 0;
|
|
|
if (tree == null) { // The case of the empty tree is treated separately.
|
|
|
count++;
|
|
|
- tree = lastEntry = firstEntry = new Entry<>(value);
|
|
|
+ tree = lastEntry = firstEntry = new Node<>(value);
|
|
|
} else {
|
|
|
- Entry<K> pnode = tree, enode;
|
|
|
+ Node<K> pnode = tree, enode;
|
|
|
int cmp, i = 0;
|
|
|
while (true) {
|
|
|
if ((cmp = compare(value, pnode.key)) == 0) {
|
|
|
@@ -226,7 +226,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
if (dirPath[ i++] = cmp > 0) {
|
|
|
if (pnode.succ()) {
|
|
|
count++;
|
|
|
- enode = new Entry<>(value);
|
|
|
+ enode = new Node<>(value);
|
|
|
if (pnode.right == null) {
|
|
|
lastEntry = enode;
|
|
|
}
|
|
|
@@ -239,7 +239,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
} else {
|
|
|
if (pnode.pred()) {
|
|
|
count++;
|
|
|
- enode = new Entry<>(value);
|
|
|
+ enode = new Node<>(value);
|
|
|
if (pnode.left == null) {
|
|
|
firstEntry = enode;
|
|
|
}
|
|
|
@@ -254,14 +254,14 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
maxDepth = i--;
|
|
|
while (i > 0 && !nodePath[ i].black()) {
|
|
|
if (!dirPath[ i - 1]) {
|
|
|
- Entry<K> ynode = nodePath[ i - 1].right;
|
|
|
+ Node<K> ynode = nodePath[ i - 1].right;
|
|
|
if (!nodePath[ i - 1].succ() && !ynode.black()) {
|
|
|
nodePath[ i].black(true);
|
|
|
ynode.black(true);
|
|
|
nodePath[ i - 1].black(false);
|
|
|
i -= 2;
|
|
|
} else {
|
|
|
- Entry<K> xnode;
|
|
|
+ Node<K> xnode;
|
|
|
if (!dirPath[ i]) {
|
|
|
ynode = nodePath[ i];
|
|
|
} else {
|
|
|
@@ -296,14 +296,14 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
- Entry<K> ynode = nodePath[ i - 1].left;
|
|
|
+ Node<K> ynode = nodePath[ i - 1].left;
|
|
|
if (!nodePath[ i - 1].pred() && !ynode.black()) {
|
|
|
nodePath[ i].black(true);
|
|
|
ynode.black(true);
|
|
|
nodePath[ i - 1].black(false);
|
|
|
i -= 2;
|
|
|
} else {
|
|
|
- Entry<K> xnode;
|
|
|
+ Node<K> xnode;
|
|
|
if (dirPath[ i]) {
|
|
|
ynode = nodePath[ i];
|
|
|
} else {
|
|
|
@@ -354,7 +354,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
if (tree == null) {
|
|
|
return false;
|
|
|
}
|
|
|
- Entry<K> entry = tree;
|
|
|
+ Node<K> entry = tree;
|
|
|
int cmp;
|
|
|
int i = 0;
|
|
|
final K kkey = (K) value;
|
|
|
@@ -413,7 +413,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
}
|
|
|
} else {
|
|
|
boolean color;
|
|
|
- Entry<K> rnode = entry.right;
|
|
|
+ Node<K> rnode = entry.right;
|
|
|
if (rnode.pred()) {
|
|
|
rnode.left = entry.left;
|
|
|
rnode.pred(entry.pred());
|
|
|
@@ -435,7 +435,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
dirPath[ i] = true;
|
|
|
nodePath[ i++] = rnode;
|
|
|
} else {
|
|
|
- Entry<K> snode;
|
|
|
+ Node<K> snode;
|
|
|
int j = i++;
|
|
|
while (true) {
|
|
|
dirPath[ i] = false;
|
|
|
@@ -478,14 +478,14 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
for (; i > 0; i--) {
|
|
|
if (dirPath[ i - 1] && !nodePath[ i - 1].succ()
|
|
|
|| !dirPath[ i - 1] && !nodePath[ i - 1].pred()) {
|
|
|
- Entry<K> xnode = dirPath[ i - 1] ? nodePath[ i - 1].right : nodePath[ i - 1].left;
|
|
|
+ Node<K> xnode = dirPath[ i - 1] ? nodePath[ i - 1].right : nodePath[ i - 1].left;
|
|
|
if (!xnode.black()) {
|
|
|
xnode.black(true);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!dirPath[ i - 1]) {
|
|
|
- Entry<K> wnode = nodePath[ i - 1].right;
|
|
|
+ Node<K> wnode = nodePath[ i - 1].right;
|
|
|
if (!wnode.black()) {
|
|
|
wnode.black(true);
|
|
|
nodePath[ i - 1].black(false);
|
|
|
@@ -513,7 +513,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
wnode.black(false);
|
|
|
} else {
|
|
|
if (wnode.succ() || wnode.right.black()) {
|
|
|
- Entry<K> ynode = wnode.left;
|
|
|
+ Node<K> ynode = wnode.left;
|
|
|
ynode.black(true);
|
|
|
wnode.black(false);
|
|
|
wnode.left = ynode.right;
|
|
|
@@ -545,7 +545,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
- Entry<K> wnode = nodePath[ i - 1].left;
|
|
|
+ Node<K> wnode = nodePath[ i - 1].left;
|
|
|
if (!wnode.black()) {
|
|
|
wnode.black(true);
|
|
|
nodePath[ i - 1].black(false);
|
|
|
@@ -573,7 +573,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
wnode.black(false);
|
|
|
} else {
|
|
|
if (wnode.pred() || wnode.left.black()) {
|
|
|
- Entry<K> ynode = wnode.right;
|
|
|
+ Node<K> ynode = wnode.right;
|
|
|
ynode.black(true);
|
|
|
wnode.black(false);
|
|
|
wnode.right = ynode.left;
|
|
|
@@ -621,7 +621,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public boolean contains(Object value) {
|
|
|
- return findKey((K) value) != null;
|
|
|
+ return findNode((K) value) != null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -691,9 +691,9 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* tree.
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- private Entry<K> readTree(java.io.ObjectInputStream istream, int n, Entry<K> pred, Entry<K> succ) throws java.io.IOException, ClassNotFoundException {
|
|
|
+ private Node<K> readTree(java.io.ObjectInputStream istream, int n, Node<K> pred, Node<K> succ) throws java.io.IOException, ClassNotFoundException {
|
|
|
if (n == 1) {
|
|
|
- final Entry<K> top = new Entry<>((K) istream.readObject());
|
|
|
+ final Node<K> top = new Node<>((K) istream.readObject());
|
|
|
top.pred(pred);
|
|
|
top.succ(succ);
|
|
|
top.black(true);
|
|
|
@@ -702,9 +702,9 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
if (n == 2) {
|
|
|
/* We handle separately this case so that recursion will
|
|
|
*always* be on nonempty subtrees. */
|
|
|
- final Entry<K> top = new Entry<>((K) istream.readObject());
|
|
|
+ final Node<K> top = new Node<>((K) istream.readObject());
|
|
|
top.black(true);
|
|
|
- top.right(new Entry<>((K) istream.readObject()));
|
|
|
+ top.right(new Node<>((K) istream.readObject()));
|
|
|
top.right.pred(top);
|
|
|
top.pred(pred);
|
|
|
top.right.succ(succ);
|
|
|
@@ -712,7 +712,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
}
|
|
|
// The right subtree is the largest one.
|
|
|
final int rightN = n / 2, leftN = n - rightN - 1;
|
|
|
- final Entry<K> top = new Entry<>();
|
|
|
+ final Node<K> top = new Node<>();
|
|
|
top.left(readTree(istream, leftN, pred, top));
|
|
|
top.key = (K) istream.readObject();
|
|
|
top.black(true);
|
|
|
@@ -728,7 +728,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
allocatePaths();
|
|
|
if (count != 0) {
|
|
|
tree = readTree(istream, count, null, null);
|
|
|
- Entry<K> entry;
|
|
|
+ Node<K> entry;
|
|
|
entry = tree;
|
|
|
while (entry.left() != null) {
|
|
|
entry = entry.left();
|
|
|
@@ -745,13 +745,13 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
/**
|
|
|
* This class represent an entry in a tree set.
|
|
|
*
|
|
|
- * <P>We use the only "metadata", i.e., {@link Entry#info}, end store
|
|
|
+ * <P>We use the only "metadata", i.e., {@link Node#info}, end store
|
|
|
* information about color, predecessor status and successor status.
|
|
|
*
|
|
|
* <P>Note that since the class is recursive, it can be considered
|
|
|
* equivalently a tree.
|
|
|
*/
|
|
|
- protected static final class Entry<K> {
|
|
|
+ private static final class Node<K> {
|
|
|
|
|
|
/**
|
|
|
* The the bit in this mask is true, the node is black.
|
|
|
@@ -769,22 +769,20 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* The key of this entry.
|
|
|
*/
|
|
|
K key;
|
|
|
- /**
|
|
|
- * The pointers to the left and right subtrees.
|
|
|
- */
|
|
|
- Entry<K> left,
|
|
|
|
|
|
/**
|
|
|
- * The pointers end the left and right subtrees.
|
|
|
- */
|
|
|
- right;
|
|
|
+ * The pointers to the left and right subtrees.
|
|
|
+ */
|
|
|
+ Node<K> left;
|
|
|
+
|
|
|
+ Node<K> right;
|
|
|
/**
|
|
|
* This integers holds different information in different bits (see
|
|
|
* {@link #SUCC_MASK}, {@link #PRED_MASK} and {@link #BLACK_MASK}).
|
|
|
*/
|
|
|
int info;
|
|
|
|
|
|
- Entry() {
|
|
|
+ Node() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -792,7 +790,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*
|
|
|
* @param key a key.
|
|
|
*/
|
|
|
- Entry(K key) {
|
|
|
+ Node(K key) {
|
|
|
this.key = key;
|
|
|
info = SUCC_MASK | PRED_MASK;
|
|
|
}
|
|
|
@@ -803,7 +801,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the left subtree (<code>null</code> if the left subtree is
|
|
|
* empty).
|
|
|
*/
|
|
|
- Entry<K> left() {
|
|
|
+ Node<K> left() {
|
|
|
return (info & PRED_MASK) != 0 ? null : left;
|
|
|
}
|
|
|
|
|
|
@@ -813,7 +811,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the right subtree (<code>null</code> if the right subtree is
|
|
|
* empty).
|
|
|
*/
|
|
|
- Entry<K> right() {
|
|
|
+ Node<K> right() {
|
|
|
return (info & SUCC_MASK) != 0 ? null : right;
|
|
|
}
|
|
|
|
|
|
@@ -868,7 +866,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*
|
|
|
* @param pred the predecessr.
|
|
|
*/
|
|
|
- void pred(Entry<K> pred) {
|
|
|
+ void pred(Node<K> pred) {
|
|
|
info |= PRED_MASK;
|
|
|
left = pred;
|
|
|
}
|
|
|
@@ -878,7 +876,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*
|
|
|
* @param succ the successor.
|
|
|
*/
|
|
|
- void succ(Entry<K> succ) {
|
|
|
+ void succ(Node<K> succ) {
|
|
|
info |= SUCC_MASK;
|
|
|
right = succ;
|
|
|
}
|
|
|
@@ -888,7 +886,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*
|
|
|
* @param left the new left subtree.
|
|
|
*/
|
|
|
- void left(Entry<K> left) {
|
|
|
+ void left(Node<K> left) {
|
|
|
info &= ~PRED_MASK;
|
|
|
this.left = left;
|
|
|
}
|
|
|
@@ -898,7 +896,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
*
|
|
|
* @param right the new right subtree.
|
|
|
*/
|
|
|
- void right(Entry<K> right) {
|
|
|
+ void right(Node<K> right) {
|
|
|
info &= ~SUCC_MASK;
|
|
|
this.right = right;
|
|
|
}
|
|
|
@@ -932,8 +930,8 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the next entry (<code>null</code>) if this is the last
|
|
|
* entry).
|
|
|
*/
|
|
|
- Entry<K> next() {
|
|
|
- Entry<K> next = this.right;
|
|
|
+ Node<K> next() {
|
|
|
+ Node<K> next = this.right;
|
|
|
if ((info & SUCC_MASK) == 0) {
|
|
|
while ((next.info & PRED_MASK) == 0) {
|
|
|
next = next.left;
|
|
|
@@ -948,8 +946,8 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the previous entry (<code>null</code>) if this is the first
|
|
|
* entry).
|
|
|
*/
|
|
|
- Entry<K> prev() {
|
|
|
- Entry<K> prev = this.left;
|
|
|
+ Node<K> prev() {
|
|
|
+ Node<K> prev = this.left;
|
|
|
if ((info & PRED_MASK) == 0) {
|
|
|
while ((prev.info & SUCC_MASK) == 0) {
|
|
|
prev = prev.right;
|
|
|
@@ -958,25 +956,6 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
return prev;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean equals(Object object) {
|
|
|
- if (!(object instanceof Entry)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- Entry<?> entry = (Entry<?>) object;
|
|
|
- return ((key) == null ? (entry.key) == null : (key).equals(entry.key));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- return ((key) == null ? 0 : (key).hashCode());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String toString() {
|
|
|
- return String.valueOf(key);
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -991,18 +970,18 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* {@link java.util.ListIterator#previous()} (or
|
|
|
* <code>null</code> if no previous entry exists).
|
|
|
*/
|
|
|
- Entry<K> prev;
|
|
|
+ Node<K> prev;
|
|
|
/**
|
|
|
* The entry that will be returned by the next call end
|
|
|
* {@link java.util.ListIterator#next()} (or
|
|
|
* <code>null</code> if no next entry exists).
|
|
|
*/
|
|
|
- Entry<K> next;
|
|
|
+ Node<K> next;
|
|
|
/**
|
|
|
* The last entry that was returned (or
|
|
|
* <code>null</code> if we did not iterate or used {@link #remove()}).
|
|
|
*/
|
|
|
- Entry<K> curr;
|
|
|
+ Node<K> curr;
|
|
|
/**
|
|
|
* The current index (in the sense of a {@link java.util.ListIterator}).
|
|
|
* Note that this value is not meaningful when this iterator has been
|
|
|
@@ -1015,7 +994,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
}
|
|
|
|
|
|
TreeIterator(K key) {
|
|
|
- if ((next = locateKey(key)) != null) {
|
|
|
+ if ((next = locateNode(key)) != null) {
|
|
|
if (compare(next.key, key) <= 0) {
|
|
|
prev = next;
|
|
|
next = next.next();
|
|
|
@@ -1039,7 +1018,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
next = next.next();
|
|
|
}
|
|
|
|
|
|
- Entry<K> nextEntry() {
|
|
|
+ Node<K> nextEntry() {
|
|
|
if (!hasNext()) {
|
|
|
throw new NoSuchElementException();
|
|
|
}
|
|
|
@@ -1063,7 +1042,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
prev = prev.prev();
|
|
|
}
|
|
|
|
|
|
- Entry<K> previousEntry() {
|
|
|
+ Node<K> previousEntry() {
|
|
|
if (!hasPrevious()) {
|
|
|
throw new NoSuchElementException();
|
|
|
}
|
|
|
@@ -1126,16 +1105,16 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the first entry of this subset, or <code>null</code> if the
|
|
|
* subset is empty.
|
|
|
*/
|
|
|
- public RBTreeSet.Entry<K> firstEntry() {
|
|
|
+ public RBTreeSet.Node<K> firstEntry() {
|
|
|
if (tree == null) {
|
|
|
return null;
|
|
|
}
|
|
|
// If this subset goes end -infinity, we return the main set first entry; otherwise, we locate the start of the set.
|
|
|
- RBTreeSet.Entry<K> entry;
|
|
|
+ RBTreeSet.Node<K> entry;
|
|
|
if (bottom) {
|
|
|
entry = firstEntry;
|
|
|
} else {
|
|
|
- entry = locateKey(begin);
|
|
|
+ entry = locateNode(begin);
|
|
|
// If we find either the start or something greater we're OK.
|
|
|
if (compare(entry.key, begin) < 0) {
|
|
|
entry = entry.next();
|
|
|
@@ -1154,16 +1133,16 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
* @return the last entry of this subset, or <code>null</code> if the
|
|
|
* subset is empty.
|
|
|
*/
|
|
|
- public RBTreeSet.Entry<K> lastEntry() {
|
|
|
+ public RBTreeSet.Node<K> lastEntry() {
|
|
|
if (tree == null) {
|
|
|
return null;
|
|
|
}
|
|
|
// If this subset goes end infinity, we return the main set last entry; otherwise, we locate the end of the set.
|
|
|
- RBTreeSet.Entry<K> entry;
|
|
|
+ RBTreeSet.Node<K> entry;
|
|
|
if (top) {
|
|
|
entry = lastEntry;
|
|
|
} else {
|
|
|
- entry = locateKey(end);
|
|
|
+ entry = locateNode(end);
|
|
|
// If we find something smaller than the end we're OK.
|
|
|
if (compare(entry.key, end) >= 0) {
|
|
|
entry = entry.prev();
|
|
|
@@ -1178,7 +1157,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
|
|
|
@Override
|
|
|
public K first() {
|
|
|
- RBTreeSet.Entry<K> entry = firstEntry();
|
|
|
+ RBTreeSet.Node<K> entry = firstEntry();
|
|
|
if (entry == null) {
|
|
|
throw new NoSuchElementException();
|
|
|
}
|
|
|
@@ -1187,7 +1166,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
|
|
|
@Override
|
|
|
public K last() {
|
|
|
- RBTreeSet.Entry<K> entry = lastEntry();
|
|
|
+ RBTreeSet.Node<K> entry = lastEntry();
|
|
|
if (entry == null) {
|
|
|
throw new NoSuchElementException();
|
|
|
}
|
|
|
@@ -1208,7 +1187,7 @@ public class RBTreeSet<K> extends ASortedSet<K> implements java.io.Serializable
|
|
|
} else if (!top && compare(key, (prev = lastEntry()).key) >= 0) {
|
|
|
next = null;
|
|
|
} else {
|
|
|
- next = locateKey(key);
|
|
|
+ next = locateNode(key);
|
|
|
if (compare(next.key, key) <= 0) {
|
|
|
prev = next;
|
|
|
next = next.next();
|