New Features

- Added: OpenHashSets now implement foreach and have less overhead.
- Added: ImmutableOpenHashSet that is not editable (is linked by default
for fast iteration)
This commit is contained in:
2021-06-25 14:22:22 +02:00
parent 2b408fb2b2
commit b784041894
6 changed files with 470 additions and 1 deletions
@@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
#if TYPE_OBJECT
import java.util.Objects;
import java.util.function.Consumer;
#endif
import speiger.src.collections.PACKAGE.collections.COLLECTION;
@@ -17,6 +18,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
#if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.PACKAGE.functions.CONSUMER;
#endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
#if !TYPE_OBJECT
@@ -374,6 +376,15 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
return result;
}
@Override
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
int index = firstIndex;
while(index != -1){
action.accept(keys[index]);
index = (int)links[index];
}
}
@Override
protected void onNodeAdded(int pos) {
if(size == 0) {