diff --git a/Changelog.md b/Changelog.md index 892b43a..a0cad17 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,8 +4,11 @@ ### Version 0.3.1 - Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants. - Fixed: HashMap wasn't deleting Keys & Values references when removing a Object -- Fixed: AVLTreeSet didn't balance properly. +- Fixed: AVLTreeMap didn't balance properly. - Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11 +- Added: HashMaps now implement ITrimmable +- Added: AVLTreeSet didn't balance properly +- Fixed: HashMaps & LinkedMaps weren't clearing references properly. ### Version 0.3.0 (Breaking 0.2.0) - Added: Stack.isEmpty was missing diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 6f42058..1d58eec 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -481,7 +481,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M } else if(lastIndex == pos) { lastIndex = (int)(links[pos] >>> 32); - if(0 <= lastIndex) links[pos] |= 0xFFFFFFFFL; + if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; } else { long link = links[pos]; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index fc9f90f..e73e0db 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -566,6 +566,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL } protected VALUE_TYPE removeIndex(int pos) { + if(pos == nullIndex) return containsNull ? removeNullIndex() : getDefaultReturnValue(); VALUE_TYPE value = values[pos]; keys[pos] = EMPTY_KEY_VALUE; values[pos] = EMPTY_VALUE; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 5470566..baa92f3 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -461,7 +461,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G } else if(lastIndex == pos) { lastIndex = (int)(links[pos] >>> 32); - if(0 <= lastIndex) links[pos] |= 0xFFFFFFFFL; + if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; } else { long link = links[pos]; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index 832f687..8ba1fcf 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -526,6 +526,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE } protected VALUE_TYPE removeIndex(int pos) { + if(pos == nullIndex) return containsNull ? removeNullIndex() : getDefaultReturnValue(); VALUE_TYPE value = values[pos]; keys[pos] = EMPTY_KEY_VALUE; values[pos] = EMPTY_VALUE; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template index 9f08bf0..4580e4d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/LinkedEnumMap.template @@ -280,7 +280,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA } else if(lastIndex == pos) { lastIndex = (int)(links[pos] >>> 32); - if(0 <= lastIndex) links[pos] |= 0xFFFFFFFFL; + if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; } else { long link = links[pos]; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template index 7d6e443..75a5732 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template @@ -801,6 +801,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ else entry.parent.right = right; right.left = entry; entry.parent = right; + entry.updateHeight(); + right.updateHeight(); } } @@ -815,6 +817,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ else entry.parent.left = left; left.right = entry; entry.parent = left; + entry.updateHeight(); + left.updateHeight(); } } @@ -1933,7 +1937,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); } - int getBalance() { return (left == null ? -1 : left.getHeight()) - (right == null ? -1 : right.getBalance()); } + int getBalance() { return (left == null ? -1 : left.getHeight()) - (right == null ? -1 : right.getHeight()); } boolean needsSuccessor() { return left != null && right != null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template index 9f50a18..3c25350 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/AVLTreeSet.template @@ -549,6 +549,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE else entry.parent.right = right; right.left = entry; entry.parent = right; + entry.updateHeight(); + right.updateHeight(); } } @@ -564,6 +566,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE else entry.parent.left = left; left.right = entry; entry.parent = left; + entry.updateHeight(); + left.updateHeight(); } } @@ -1120,9 +1124,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE int getHeight() { return state; } - void updateHeight() { state = (1 + Math.max(left == null ? 0 : left.getHeight(), right == null ? 0 : right.getHeight())); } + void updateHeight() { state = (1 + Math.max(left == null ? -1 : left.getHeight(), right == null ? -1 : right.getHeight())); } - int getBalance() { return (left == null ? 0 : left.getHeight()) - (right == null ? 0 : right.getBalance()); } + int getBalance() { return (left == null ? -1 : left.getHeight()) - (right == null ? -1 : right.getHeight()); } boolean needsSuccessor() { return left != null && right != null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index 2a67b26..df9b3ca 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -424,7 +424,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY } else if(lastIndex == pos) { lastIndex = (int)(links[pos] >>> 32); - if(0 <= lastIndex) links[pos] |= 0xFFFFFFFFL; + if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; } else { long link = links[pos]; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index 89bd7a5..61ae67e 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -396,7 +396,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE } else if(lastIndex == pos) { lastIndex = (int)(links[pos] >>> 32); - if(0 <= lastIndex) links[pos] |= 0xFFFFFFFFL; + if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL; } else { long link = links[pos]; diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index 0942970..b1eedc1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -366,6 +366,8 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T } protected boolean removeIndex(int pos) { + if(pos == nullIndex) return containsNull ? removeNullIndex() : false; + keys[pos] = EMPTY_KEY_VALUE; size--; onNodeRemoved(pos); shiftKeys(pos); diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index 63cce66..e05be61 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -283,7 +283,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp @Override public boolean remove(KEY_TYPE o) { - if(KEY_EQUALS_NULL(o)) return (containsNull ? removeNullIndex() : false); + if(KEY_EQUALS_NULL(o)) return containsNull ? removeNullIndex() : false; int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask; KEY_TYPE current = keys[pos]; if(KEY_EQUALS_NULL(current)) return false; @@ -324,6 +324,8 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp } protected boolean removeIndex(int pos) { + if(pos == nullIndex) return containsNull ? removeNullIndex() : false; + keys[pos] = EMPTY_KEY_VALUE; size--; onNodeRemoved(pos); shiftKeys(pos);