mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +00:00
Merge pull request #3 from mkeesey/master
TreeSet defers to underlying set for determining size instead of keeping its own tally
This commit is contained in:
commit
392120dd7d
@ -15,7 +15,6 @@ import avian.Cell;
|
|||||||
|
|
||||||
public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
||||||
private PersistentSet<Cell<T>> set;
|
private PersistentSet<Cell<T>> set;
|
||||||
private int size;
|
|
||||||
|
|
||||||
public TreeSet(final Comparator<T> comparator) {
|
public TreeSet(final Comparator<T> comparator) {
|
||||||
set = new PersistentSet(new Comparator<Cell<T>>() {
|
set = new PersistentSet(new Comparator<Cell<T>>() {
|
||||||
@ -23,7 +22,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
return comparator.compare(a.value, b.value);
|
return comparator.compare(a.value, b.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
size = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeSet() {
|
public TreeSet() {
|
||||||
@ -66,7 +64,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
PersistentSet.Path<Cell<T>> p = set.find(new Cell(value, null));
|
PersistentSet.Path<Cell<T>> p = set.find(new Cell(value, null));
|
||||||
if (p.fresh()) {
|
if (p.fresh()) {
|
||||||
set = p.add();
|
set = p.add();
|
||||||
++size;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -76,7 +73,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
PersistentSet.Path<Cell<T>> p = set.find(new Cell(value, null));
|
PersistentSet.Path<Cell<T>> p = set.find(new Cell(value, null));
|
||||||
if (p.fresh()) {
|
if (p.fresh()) {
|
||||||
set = p.add();
|
set = p.add();
|
||||||
++size;
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
T old = p.value().value;
|
T old = p.value().value;
|
||||||
@ -100,8 +96,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
if (p.fresh()) {
|
if (p.fresh()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
--size;
|
|
||||||
|
|
||||||
Cell<T> old = p.value();
|
Cell<T> old = p.value();
|
||||||
|
|
||||||
if (p.value().next != null) {
|
if (p.value().next != null) {
|
||||||
@ -119,11 +113,11 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return size;
|
return set.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return size == 0;
|
return set.size() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Object value) {
|
public boolean contains(Object value) {
|
||||||
@ -132,7 +126,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
set = new PersistentSet(set.comparator());
|
set = new PersistentSet(set.comparator());
|
||||||
size = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MyIterator<T> implements java.util.Iterator<T> {
|
private class MyIterator<T> implements java.util.Iterator<T> {
|
||||||
@ -180,8 +173,6 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
|
|||||||
public void remove() {
|
public void remove() {
|
||||||
if (! canRemove) throw new IllegalStateException();
|
if (! canRemove) throw new IllegalStateException();
|
||||||
|
|
||||||
--size;
|
|
||||||
|
|
||||||
if (prevPrevCell != null && prevPrevCell.next == prevCell) {
|
if (prevPrevCell != null && prevPrevCell.next == prevCell) {
|
||||||
// cell to remove is not the first in the list.
|
// cell to remove is not the first in the list.
|
||||||
prevPrevCell.next = prevCell.next;
|
prevPrevCell.next = prevCell.next;
|
||||||
|
Loading…
Reference in New Issue
Block a user