Adding more JavaDoc (fixing roughly 8k javadoc errors)
-Added: JavaDocs to Map classes/constructors -Added: JavaDocs to the Maps Class
This commit is contained in:
+95
@@ -34,30 +34,79 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
/**
|
||||
* A Type Specific LinkedHashMap that allows for custom HashControl. That uses arrays to create links between nodes.
|
||||
* For cases where Objects/primitive do not allow hashcoding this can be really useful and provide a lot of control.
|
||||
* This implementation of SortedMap does not support SubMaps of any kind. It implements the interface due to sortability and first/last access
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected transient long[] links;
|
||||
/** The First Index in the Map */
|
||||
protected int firstIndex = -1;
|
||||
/** The Last Index in the Map */
|
||||
protected int lastIndex = -1;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(int minCapacity, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity and load factor
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(int minCapacity, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
super(minCapacity, loadFactor, strategy);
|
||||
links = new long[nullIndex + 1];
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys.length, loadFactor, strategy);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -65,29 +114,75 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys.length, loadFactor, strategy);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map.size(), loadFactor, strategy);
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map.size(), loadFactor, strategy);
|
||||
putAll(map);
|
||||
|
||||
+105
-1
@@ -31,31 +31,71 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
/**
|
||||
* A Type Specific HashMap that allows for custom HashControl.
|
||||
* For cases where Objects/primitive do not allow hashcoding this can be really useful and provide a lot of control.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
/** The Backing values array */
|
||||
protected transient VALUE_TYPE[] values;
|
||||
/** If a null value is present */
|
||||
protected transient boolean containsNull;
|
||||
/** Minimum array size the HashMap will be */
|
||||
protected transient int minCapacity;
|
||||
/** Index of the Null Value */
|
||||
protected transient int nullIndex;
|
||||
/** Maximum amount of Values that can be stored before the array gets expanded usually 75% */
|
||||
protected transient int maxFill;
|
||||
/** Max Index that is allowed to be searched through nullIndex - 1 */
|
||||
protected transient int mask;
|
||||
/** EntrySet cache */
|
||||
protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
/** KeySet cache */
|
||||
protected transient SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
/** How full the Arrays are allowed to get before resize */
|
||||
protected final float loadFactor;
|
||||
/** Strategy that allows to control the Hash Generation and equals comparason */
|
||||
protected final STRATEGY KEY_SUPER_GENERIC_TYPE strategy;
|
||||
|
||||
|
||||
/**
|
||||
* Default Contstructor
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(int minCapacity, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity and load factor
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(int minCapacity, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
if(loadFactor <= 0 || loadFactor >= 1F) throw new IllegalStateException("Load Factor is not between 0 and 1");
|
||||
@@ -69,10 +109,28 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys.length, loadFactor, strategy);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -80,29 +138,75 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(keys.length, loadFactor, strategy);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map.size(), loadFactor, strategy);
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR, strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @param strategy the strategy that allows hash control.
|
||||
* @throws NullPointerException if Strategy is null
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public CUSTOM_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(map.size(), loadFactor, strategy);
|
||||
putAll(map);
|
||||
|
||||
+73
@@ -36,30 +36,69 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
/**
|
||||
* A Type Specific LinkedHashMap implementation that uses specific arrays to create links between nodes to remove the wrapping of elements
|
||||
* to greatly reduce memory usage. In Addition adding some helper methods to move around elements.
|
||||
* This implementation of SortedMap does not support SubMaps of any kind. It implements the interface due to sortability and first/last access
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected long[] links;
|
||||
/** The First Index in the Map */
|
||||
protected int firstIndex = -1;
|
||||
/** The Last Index in the Map */
|
||||
protected int lastIndex = -1;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public LINKED_HASH_MAP() {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
*/
|
||||
public LINKED_HASH_MAP(int minCapacity) {
|
||||
this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity and load factor
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_HASH_MAP(int minCapacity, float loadFactor) {
|
||||
super(minCapacity, loadFactor);
|
||||
links = new long[nullIndex + 1];
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor) {
|
||||
this(keys.length, loadFactor);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -67,29 +106,63 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public LINKED_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor) {
|
||||
this(keys.length, loadFactor);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public LINKED_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, float loadFactor) {
|
||||
this(map.size(), loadFactor);
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public LINKED_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public LINKED_HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor) {
|
||||
this(map.size(), loadFactor);
|
||||
putAll(map);
|
||||
|
||||
+82
@@ -30,30 +30,64 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
/**
|
||||
* A Type Specific Custom implementation of the HashMap
|
||||
* Instead of using Wrapper Object Arrays for storing keys and values there is dedicated arrays for storing keys and values.
|
||||
* Extra to that there is a couple quality of life functions provided
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
/** The Backing values array */
|
||||
protected transient VALUE_TYPE[] values;
|
||||
/** If a null value is present */
|
||||
protected transient boolean containsNull;
|
||||
/** Minimum array size the HashMap will be */
|
||||
protected transient int minCapacity;
|
||||
/** Index of the Null Value */
|
||||
protected transient int nullIndex;
|
||||
/** Maximum amount of Values that can be stored before the array gets expanded usually 75% */
|
||||
protected transient int maxFill;
|
||||
/** Max Index that is allowed to be searched through nullIndex - 1 */
|
||||
protected transient int mask;
|
||||
/** EntrySet cache */
|
||||
protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
/** KeySet cache */
|
||||
protected transient SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
/** How full the Arrays are allowed to get before resize */
|
||||
protected final float loadFactor;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public HASH_MAP() {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
*/
|
||||
public HASH_MAP(int minCapacity) {
|
||||
this(minCapacity, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity and load factor
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public HASH_MAP(int minCapacity, float loadFactor) {
|
||||
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
if(loadFactor <= 0 || loadFactor >= 1F) throw new IllegalStateException("Load Factor is not between 0 and 1");
|
||||
@@ -66,10 +100,24 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public HASH_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, float loadFactor) {
|
||||
this(keys.length, loadFactor);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -77,29 +125,63 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public HASH_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, float loadFactor) {
|
||||
this(keys.length, loadFactor);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public HASH_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, float loadFactor) {
|
||||
this(map.size(), loadFactor);
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, HashUtil.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param loadFactor the percentage of how full the backing array can be before they resize
|
||||
* @throws IllegalStateException if the loadfactor is either below/equal to 0 or above/equal to 1
|
||||
*/
|
||||
public HASH_MAP(MAP KEY_VALUE_GENERIC_TYPE map, float loadFactor) {
|
||||
this(map.size(), loadFactor);
|
||||
putAll(map);
|
||||
|
||||
+59
@@ -40,19 +40,44 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
/**
|
||||
* A Very Specific Type Specific implementation of a ArrayMap.
|
||||
* This type of map is for very specific use cases that usaully would have lead to Tupled Lists otherwise.
|
||||
* It also does not allow duplication (except for array constructors) and checks from last to first.
|
||||
* It is not designed to be used as a HashMap replacement due to the poor performance it would cause.
|
||||
* @note in this implementation SubMaps do NOT keep track of parent changes fully. For performance reasons it will just have a start/end index and not values
|
||||
* Anything within that range will be updated appropiatly a shrink/growth of elements will break SubMaps in some ways. This can be useful but be careful
|
||||
* @note this implementation does not shrink and only grows.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
/** The Backing values array */
|
||||
protected transient VALUE_TYPE[] values;
|
||||
/** Amount of Elements stored in the ArrayMap */
|
||||
protected int size = 0;
|
||||
/** KeySet cache */
|
||||
protected SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
/** EntrySet cache */
|
||||
protected FastSortedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public ARRAY_MAP() {
|
||||
this(HashUtil.DEFAULT_MIN_CAPACITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that defines the minimum capacity
|
||||
* @param minCapacity the minimum capacity the HashMap is allowed to be.
|
||||
* @throws IllegalStateException if the minimum capacity is negative
|
||||
*/
|
||||
public ARRAY_MAP(int minCapacity) {
|
||||
if(minCapacity < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
keys = NEW_KEY_ARRAY(minCapacity);
|
||||
@@ -60,10 +85,23 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in length
|
||||
*/
|
||||
public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, keys.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them) with a custom length
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param length the amount of values that should be pulled from the array
|
||||
* @throws IllegalStateException if the keys and values do not match in length
|
||||
*/
|
||||
public ARRAY_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int length) {
|
||||
this(length);
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -75,10 +113,23 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, keys.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param length the amount of values that should be pulled from the array
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public ARRAY_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, int length) {
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
this.keys = Arrays.copyOf(keys, length);
|
||||
@@ -86,11 +137,19 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
this.size = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public ARRAY_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map.size());
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public ARRAY_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map.size());
|
||||
for(ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = MAPS.fastIterator(map);iter.hasNext();size++) {
|
||||
|
||||
+19
@@ -18,17 +18,36 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import sun.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* A Type Specific EnumMap implementation that allows for Primitive Values.
|
||||
* Unlike javas implementation this one does not jump around between a single long or long array implementation based around the enum size
|
||||
* This will cause a bit more memory usage but allows for a simpler implementation.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** Enum Type that is being used */
|
||||
protected final Class<T> keyType;
|
||||
/** The Backing keys array. */
|
||||
protected transient final T[] keys;
|
||||
/** The Backing values array */
|
||||
protected transient final VALUE_TYPE[] values;
|
||||
/** The Backing array that indicates which index is present or not */
|
||||
protected transient final long[] present;
|
||||
/** Amount of Elements stored in the ArrayMap */
|
||||
protected int size = 0;
|
||||
/** EntrySet cache */
|
||||
protected transient ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySet;
|
||||
/** KeySet cache */
|
||||
protected transient ObjectSet<T> keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param keyType the type of Enum that should be used
|
||||
*/
|
||||
public ENUM_MAP(Class<T> keyType) {
|
||||
this.keyType = keyType;
|
||||
keys = getKeyUniverse(keyType);
|
||||
|
||||
+82
-10
@@ -39,38 +39,73 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Simple Type Specific AVL TreeMap implementation that reduces boxing/unboxing.
|
||||
* It is using a bit more memory then <a href="https://github.com/vigna/fastutil">FastUtil</a>,
|
||||
* but it saves a lot of Performance on the Optimized removal and iteration logic.
|
||||
* Which makes the implementation actually useable and does not force to use Javas default implementation.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The center of the Tree */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE tree;
|
||||
/** The Lowest possible Node */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE first;
|
||||
/** The Highest possible Node */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE last;
|
||||
/** The amount of elements stored in the Map */
|
||||
protected int size = 0;
|
||||
/** The Sorter of the Tree */
|
||||
protected transient COMPARATOR KEY_GENERIC_TYPE comparator;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
protected KEY_TYPE defaultMaxNotFound = null;
|
||||
protected KEY_TYPE defaultMinNotFound = null;
|
||||
#else
|
||||
#if !TYPE_OBJECT
|
||||
/** the default return value for max searches */
|
||||
protected KEY_TYPE defaultMaxNotFound = CLASS_TYPE.MIN_VALUE;
|
||||
/** the default return value for min searches */
|
||||
protected KEY_TYPE defaultMinNotFound = CLASS_TYPE.MAX_VALUE;
|
||||
#endif
|
||||
|
||||
/** KeySet Cache */
|
||||
protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values Cache */
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE values;
|
||||
/** EntrySet Cache */
|
||||
protected ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySet;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public AVL_TREE_MAP() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows to define the sorter
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public AVL_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that has a custom sorter and allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public AVL_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -78,37 +113,74 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that has a custom sorter and allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public AVL_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public AVL_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that has a custom sorter and allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public AVL_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that has a custom sorter and allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public AVL_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; }
|
||||
public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; }
|
||||
/** only used for primitives
|
||||
* @return null
|
||||
*/
|
||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||
/** only used for primitives
|
||||
* @return null
|
||||
*/
|
||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||
|
||||
#else
|
||||
@Override
|
||||
@@ -443,25 +515,25 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
@Override
|
||||
public KEY_TYPE lowerKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findLowerNode(e);
|
||||
return node != null ? node.key : defaultMinNotFound;
|
||||
return node != null ? node.key : getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floorKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findFloorNode(e);
|
||||
return node != null ? node.key : defaultMinNotFound;
|
||||
return node != null ? node.key : getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higherKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findHigherNode(e);
|
||||
return node != null ? node.key : defaultMaxNotFound;
|
||||
return node != null ? node.key : getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceilingKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findCeilingNode(e);
|
||||
return node != null ? node.key : defaultMaxNotFound;
|
||||
return node != null ? node.key : getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+82
-10
@@ -39,38 +39,73 @@ import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Simple Type Specific RB TreeMap implementation that reduces boxing/unboxing.
|
||||
* It is using a bit more memory then <a href="https://github.com/vigna/fastutil">FastUtil</a>,
|
||||
* but it saves a lot of Performance on the Optimized removal and iteration logic.
|
||||
* Which makes the implementation actually useable and does not force to use Javas default implementation.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The center of the Tree */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE tree;
|
||||
/** The Lowest possible Node */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE first;
|
||||
/** The Highest possible Node */
|
||||
protected transient Entry KEY_VALUE_GENERIC_TYPE last;
|
||||
/** The amount of elements stored in the Map */
|
||||
protected int size = 0;
|
||||
/** The Sorter of the Tree */
|
||||
protected transient COMPARATOR KEY_GENERIC_TYPE comparator;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
protected KEY_TYPE defaultMaxNotFound = null;
|
||||
protected KEY_TYPE defaultMinNotFound = null;
|
||||
#else
|
||||
#if !TYPE_OBJECT
|
||||
/** the default return value for max searches */
|
||||
protected KEY_TYPE defaultMaxNotFound = CLASS_TYPE.MIN_VALUE;
|
||||
/** the default return value for min searches */
|
||||
protected KEY_TYPE defaultMinNotFound = CLASS_TYPE.MAX_VALUE;
|
||||
#endif
|
||||
|
||||
/** KeySet Cache */
|
||||
protected NAVIGABLE_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values Cache */
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE values;
|
||||
/** EntrySet Cache */
|
||||
protected ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySet;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public RB_TREE_MAP() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows to define the sorter
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public RB_TREE_MAP(COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* Helper constructor that allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that has a custom sorter and allow to create a map from boxed values (it will unbox them)
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public RB_TREE_MAP(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
@@ -78,37 +113,74 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Helper constructor that allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||
this(keys, values, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper constructor that has a custom sorter and allow to create a map from unboxed values
|
||||
* @param keys the keys that should be put into the map
|
||||
* @param values the values that should be put into the map.
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||
*/
|
||||
public RB_TREE_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
if(keys.length != values.length) throw new IllegalStateException("Input Arrays are not equal size");
|
||||
for(int i = 0,m=keys.length;i<m;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public RB_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper constructor that has a custom sorter and allows to create a Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public RB_TREE_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
*/
|
||||
public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Type Specific Helper function that has a custom sorter and allows to create a new Map with exactly the same values as the provided map.
|
||||
* @param map the values that should be present in the map
|
||||
* @param comp the function that decides how the tree is sorted, can be null
|
||||
*/
|
||||
public RB_TREE_MAP(MAP KEY_VALUE_GENERIC_TYPE map, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
comparator = comp;
|
||||
putAll(map);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public KEY_TYPE getDefaultMaxValue() { return defaultMaxNotFound; }
|
||||
public KEY_TYPE getDefaultMinValue() { return defaultMinNotFound; }
|
||||
/** only used for primitives
|
||||
* @return null
|
||||
*/
|
||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||
/** only used for primitives
|
||||
* @return null
|
||||
*/
|
||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||
|
||||
#else
|
||||
@Override
|
||||
@@ -442,25 +514,25 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public KEY_TYPE lowerKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findLowerNode(e);
|
||||
return node != null ? node.key : defaultMinNotFound;
|
||||
return node != null ? node.key : getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floorKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findFloorNode(e);
|
||||
return node != null ? node.key : defaultMinNotFound;
|
||||
return node != null ? node.key : getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higherKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findHigherNode(e);
|
||||
return node != null ? node.key : defaultMaxNotFound;
|
||||
return node != null ? node.key : getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceilingKey(KEY_TYPE e) {
|
||||
Entry KEY_VALUE_GENERIC_TYPE node = findCeilingNode(e);
|
||||
return node != null ? node.key : defaultMaxNotFound;
|
||||
return node != null ? node.key : getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -142,7 +142,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* Type Specific remove function to reduce boxing/unboxing
|
||||
* @param key the element that should be removed
|
||||
* @param value the expected value that should be found
|
||||
* @return true if the key & value was found and removed
|
||||
* @return true if the key and value was found and removed
|
||||
* @see Map#remove(Object, Object)
|
||||
*/
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value);
|
||||
@@ -151,7 +151,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @see Map#remove(Object, Object)
|
||||
* @param key the element that should be removed
|
||||
* @param value the expected value that should be found
|
||||
* @return true if the key & value was found and removed
|
||||
* @return true if the key and value was found and removed
|
||||
*/
|
||||
@Override
|
||||
public default boolean remove(Object key, Object value) {
|
||||
|
||||
Reference in New Issue
Block a user