New features.
-Added: Improved Map documentation for compute methods -Added: Dedicated toArray implementations to TreeSets
This commit is contained in:
parent
2da4588430
commit
bcc2ffdc13
|
@ -2,6 +2,7 @@
|
|||
|
||||
### Version 0.8.0
|
||||
- Added: getFirst/getLast/removeFirst/removeLast to Lists
|
||||
- Added: Dedicated implementations for toArray into TreeSets
|
||||
|
||||
### Version 0.8.0
|
||||
- Added: ISizeProvider interface (Optimization Helper)
|
||||
|
|
|
@ -382,13 +382,17 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value
|
||||
* @return the result of the computation
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
|
@ -397,6 +401,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param valueProvider the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
|
@ -404,6 +410,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if present
|
||||
* @return the result of the default return value or present value
|
||||
|
@ -412,6 +420,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific merge method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be be searched for
|
||||
* @param value the value that should be merged with
|
||||
* @param mappingFunction the operator that should generate the new Value
|
||||
|
@ -421,6 +431,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Bulk method for merging Maps.
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param m the entries that should be bulk added
|
||||
* @param mappingFunction the operator that should generate the new Value
|
||||
* @note if the result matches the default return value then the key is removed from the map
|
||||
|
|
|
@ -27,6 +27,7 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
|||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
|
@ -651,6 +652,44 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
tree = null;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = entry.key;
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
obj[index++] = KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a == null) a = (E[])new Object[size()];
|
||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = (E)KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
public AVL_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
AVL_TREE_SET KEY_GENERIC_TYPE set = new AVL_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
|
|
|
@ -27,6 +27,7 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
|||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
#endif
|
||||
|
@ -652,6 +653,44 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||
tree = null;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = entry.key;
|
||||
}
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public Object[] toArray() {
|
||||
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||
Object[] obj = new Object[size()];
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
obj[index++] = KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a == null) a = (E[])new Object[size()];
|
||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||
int index = 0;
|
||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next()) {
|
||||
a[index++] = (E)KEY_TO_OBJ(entry.key);
|
||||
}
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
public RB_TREE_SET KEY_GENERIC_TYPE copy() {
|
||||
RB_TREE_SET KEY_GENERIC_TYPE set = new RB_TREE_SETBRACES();
|
||||
set.size = size;
|
||||
|
|
Loading…
Reference in New Issue