Fixed recent found bugs

-Fixed: addAll with non Specific Collections was crashing lists.
-Fixed/Refactor: Clear and trim implementation was all over the place
-Fixed: Wrappers toString/hashCode/equals function wasn't implemented
-Added: Tests for addAll bug
-Refactor: Did small code style cleanups as I was fixing bugs.
This commit is contained in:
2021-09-13 17:02:24 +02:00
parent ec817fb9c2
commit e30ca4103f
15 changed files with 197 additions and 151 deletions
@@ -354,14 +354,17 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
@Override
public void clearAndTrim(int size) {
if(nullIndex <= size) {
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
if(size >= request) {
clear();
return;
}
nullIndex = size;
mask = nullIndex - 1;
nullIndex = request;
mask = request-1;
maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1);
keys = NEW_KEY_ARRAY(nullIndex + 1);
keys = NEW_KEY_ARRAY(request + 1);
this.size = 0;
containsNull = false;
}
private void ensureCapacity(int newCapacity) {