New Features

- Added: addOrGet for sets.
- Added: Async API which allows to easily execute Iterables/Collections
offthread without the complexity.
This commit is contained in:
2022-04-07 00:04:52 +02:00
parent 29c4d253cf
commit 6f31fc5abb
15 changed files with 1168 additions and 1 deletions
@@ -235,6 +235,30 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
return true;
}
#if TYPE_OBJECT
@Override
public KEY_TYPE addOrGet(KEY_TYPE o) {
if(KEY_EQUALS_NULL(o)) {
if(containsNull) return null;
containsNull = true;
onNodeAdded(nullIndex);
}
else {
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
KEY_TYPE current = keys[pos];
if(KEY_EQUALS_NOT_NULL(current)) {
if(KEY_EQUALS(current, o)) return current;
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
if(KEY_EQUALS(current, o)) return current;
}
keys[pos] = o;
onNodeAdded(pos);
}
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
return o;
}
#endif
@Override
@Primitive
public boolean addAll(Collection<? extends CLASS_TYPE> c) {