Started working on the next patch.
- Added: ISizeProvider interface (Optimization Helper) - Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons) - Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays. - Fixed: putIfAbsent now replaces defaultValues
This commit is contained in:
+5
@@ -1812,6 +1812,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
finally {
|
||||
|
||||
+5
@@ -270,6 +270,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -245,6 +245,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
insert(-slot-1, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[slot];
|
||||
values[slot] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[slot];
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -202,6 +202,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
insertIndex(size++, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
else if(VALUE_EQUALS(values[index], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[index];
|
||||
values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -161,7 +161,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
if(isSet(index)) {
|
||||
if(VALUE_EQUALS(values[index], getDefaultReturnValue())) {
|
||||
VALUE_TYPE oldValue = values[index];
|
||||
values[index] = value;
|
||||
return oldValue;
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
set(index);
|
||||
values[index] = value;
|
||||
return getDefaultReturnValue();
|
||||
|
||||
+4
-1
@@ -280,7 +280,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
int compare = 0;
|
||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||
while(true) {
|
||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
||||
if((compare = compare(key, parent.key)) == 0) {
|
||||
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||
return parent.value;
|
||||
}
|
||||
if(compare < 0) {
|
||||
if(parent.left == null) break;
|
||||
parent = parent.left;
|
||||
|
||||
+4
-1
@@ -280,7 +280,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
int compare = 0;
|
||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||
while(true) {
|
||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
||||
if((compare = compare(key, parent.key)) == 0) {
|
||||
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||
return parent.value;
|
||||
}
|
||||
if(compare < 0) {
|
||||
if(parent.left == null) break;
|
||||
parent = parent.left;
|
||||
|
||||
+20
@@ -102,6 +102,26 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
*/
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A Helper method that allows to put int a MAP.Entry into a map.
|
||||
* @param entry then Entry that should be inserted.
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default VALUE_TYPE put(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||
return put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
/**
|
||||
* A Helper method that allows to put int a Map.Entry into a map.
|
||||
* @param entry then Entry that should be inserted.
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
|
||||
return put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
|
||||
* @param keys the keys that should be added
|
||||
|
||||
Reference in New Issue
Block a user