Fixing bugs found when implementing Bidirectional Iterator unit tests.

-Fixed: AbstractList/ImmutableList/ArraySet/ArrayMap skip/back implementation was causing crashes and didn't update the last returned value.
-Fixed: ArraySet/ArrayMap previous was not subtracting before returning value.
-Fixed: BidirectionalIterator back was calling the object variant instead of the TypeSpecific Variant.
-Fixed: TreeSets/Maps Iterator now fully supports backwards Iterating.
-Added: Specialized skip/back function to improve speed in ImmutableHashSet/LinkedHashSet/CustomLinkedHashSet
This commit is contained in:
2022-06-04 21:05:31 +02:00
parent c1862e6b05
commit 8b5e5a75c1
18 changed files with 502 additions and 175 deletions
@@ -678,6 +678,28 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
}
}
@Override
public int skip(int amount) {
int result = 0;
while(next != -1 && result != amount) {
current = previous = next;
next = (int)(links[current]);
result++;
}
return result;
}
@Override
public int back(int amount) {
int result = 0;
while(previous != -1 && result != amount) {
current = next = previous;
previous = (int)(links[current] >> 32);
result++;
}
return result;
}
@Override
public boolean hasNext() {
return next != -1;
@@ -746,9 +768,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
@Override
public KEY_TYPE PREVIOUS() {
if(!hasPrevious()) throw new NoSuchElementException();
current = previous;
current = next = previous;
previous = (int)(links[current] >> 32);
next = current;
if(index >= 0) index--;
return keys[current];
}
@@ -756,9 +777,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
@Override
public KEY_TYPE NEXT() {
if(!hasNext()) throw new NoSuchElementException();
current = next;
current = previous = next;
next = (int)(links[current]);
previous = current;
if(index >= 0) index++;
return keys[current];
}