cleanup
- Remove TODO in unionUnsorted, because I don't think there is a much better solution. - Remove TODO for lastIndexOf, because it has been implemented. - Use local variables for size in unionSorted.
This commit is contained in:
@@ -20,9 +20,8 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
// TODO support Iterator
|
// TODO support Iterator
|
||||||
// TODO add mod counts
|
// TODO add mod counts
|
||||||
// TODO support sublists
|
// TODO support sublists
|
||||||
// TODO add lastIndexOf
|
|
||||||
// TODO check that methods like intersection/union work with big arrays. They
|
// TODO check that methods like intersection/union work with big arrays. They
|
||||||
// should not try to allocate more memory MAX_ARRAY_SIZE
|
// should not try to allocate more memory than MAX_ARRAY_SIZE
|
||||||
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
||||||
// TODO removeIf see ArrayList.removeIf. Cannot handle removeIf(i -> indexOf(i)
|
// TODO removeIf see ArrayList.removeIf. Cannot handle removeIf(i -> indexOf(i)
|
||||||
// != lastIndexOf(i)) on sorted lists
|
// != lastIndexOf(i)) on sorted lists
|
||||||
@@ -984,8 +983,8 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
* <p>
|
* <p>
|
||||||
* If both lists are sorted, then the time complexity is O(n+m), where n is the
|
* If both lists are sorted, then the time complexity is O(n+m), where n is the
|
||||||
* length of the first list and m the length of the second list. If at least one
|
* length of the first list and m the length of the second list. If at least one
|
||||||
* list is not sorted, then the time complexity is O((n+m)*log(n+m)), where n is
|
* list is not sorted, then the time complexity is O(m*log(m)), where m is the
|
||||||
* the length of the shorter list and m the length of the longer list.
|
* length of the longer list.
|
||||||
*
|
*
|
||||||
* @param a
|
* @param a
|
||||||
* the first list
|
* the first list
|
||||||
@@ -1005,15 +1004,16 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static IntList unionSorted(final IntList a, final IntList b) {
|
private static IntList unionSorted(final IntList a, final IntList b) {
|
||||||
final IntList result = new IntList(a.size() + b.size());
|
|
||||||
|
|
||||||
final int aSize = a.size();
|
final int aSize = a.size();
|
||||||
final int bSize = b.size();
|
final int bSize = b.size();
|
||||||
|
|
||||||
|
final IntList result = new IntList(aSize + bSize);
|
||||||
|
|
||||||
int l = 0;
|
int l = 0;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
while (l < a.size() && r < b.size()) {
|
while (l < aSize && r < bSize) {
|
||||||
|
|
||||||
final int lv = a.get(l);
|
final int lv = a.get(l);
|
||||||
final int rv = b.get(r);
|
final int rv = b.get(r);
|
||||||
@@ -1062,9 +1062,6 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static IntList unionUnsorted(final IntList a, final IntList b) {
|
private static IntList unionUnsorted(final IntList a, final IntList b) {
|
||||||
// TODO use a more efficient algorithm. The sort operations make this 10 times
|
|
||||||
// slower than unionSorted
|
|
||||||
|
|
||||||
final IntList aSorted = new IntList(a);
|
final IntList aSorted = new IntList(a);
|
||||||
aSorted.parallelSort();
|
aSorted.parallelSort();
|
||||||
final IntList bSorted = new IntList(b);
|
final IntList bSorted = new IntList(b);
|
||||||
|
|||||||
Reference in New Issue
Block a user