Package org.agrona.collections
Class CollectionUtil
java.lang.Object
org.agrona.collections.CollectionUtil
Utility functions for collection objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> V getOrDefault
(Map<K, V> map, K key, Function<K, V> supplier) A getOrDefault that doesn't create garbage if its suppler is non-capturing.static <T> int
Remove element from a list if it matches a predicate.static <V> int
sum
(List<V> values, ToIntFunction<V> function) Garbage free sum function.static void
validateLoadFactor
(float loadFactor) Validate that a load factor is in the range of 0.1 to 0.9.static void
validatePositivePowerOfTwo
(int value) Validate that a number is a power of two.
-
Constructor Details
-
CollectionUtil
private CollectionUtil()
-
-
Method Details
-
getOrDefault
A getOrDefault that doesn't create garbage if its suppler is non-capturing.- Type Parameters:
K
- type of the keyV
- type of the value- Parameters:
map
- to perform the lookup on.key
- on which the lookup is done.supplier
- of the default value if one is not found.- Returns:
- the value if found or a new default which as been added to the map.
-
sum
Garbage free sum function.Note: the list must implement
RandomAccess
to be efficient.- Type Parameters:
V
- the value to add up- Parameters:
values
- the list of input valuesfunction
- function that map each value to an int- Returns:
- the sum of all the int values returned for each member of the list.
-
validateLoadFactor
public static void validateLoadFactor(float loadFactor) Validate that a load factor is in the range of 0.1 to 0.9.Load factors in the range 0.5 - 0.7 are recommended for open-addressing with linear probing.
- Parameters:
loadFactor
- to be validated.
-
validatePositivePowerOfTwo
public static void validatePositivePowerOfTwo(int value) Validate that a number is a power of two.- Parameters:
value
- to be validated.
-
removeIf
Remove element from a list if it matches a predicate.Note: the list must implement
RandomAccess
to be efficient.- Type Parameters:
T
- type of the value.- Parameters:
values
- to be iterated over.predicate
- to test the value against- Returns:
- the number of items remove.
-