From bfbddf3fb17fb8bece17ec291e7c322a8a1ad4f2 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 22 Jan 2018 18:50:53 +0100 Subject: [PATCH] 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. --- .../java/org/lucares/collections/IntList.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java index 7a7e375..7b4fe26 100644 --- a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java +++ b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java @@ -20,9 +20,8 @@ public final class IntList implements Serializable, Cloneable { // TODO support Iterator // TODO add mod counts // TODO support sublists - // TODO add lastIndexOf // 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 removeIf see ArrayList.removeIf. Cannot handle removeIf(i -> indexOf(i) // != lastIndexOf(i)) on sorted lists @@ -984,8 +983,8 @@ public final class IntList implements Serializable, Cloneable { *

* 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 - * list is not sorted, then the time complexity is O((n+m)*log(n+m)), where n is - * the length of the shorter list and m the length of the longer list. + * list is not sorted, then the time complexity is O(m*log(m)), where m is the + * length of the longer list. * * @param a * the first list @@ -1005,15 +1004,16 @@ public final class IntList implements Serializable, Cloneable { } 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 bSize = b.size(); + final IntList result = new IntList(aSize + bSize); + int l = 0; int r = 0; - while (l < a.size() && r < b.size()) { + while (l < aSize && r < bSize) { final int lv = a.get(l); 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) { - // TODO use a more efficient algorithm. The sort operations make this 10 times - // slower than unionSorted - final IntList aSorted = new IntList(a); aSorted.parallelSort(); final IntList bSorted = new IntList(b);