Class WeightedList<E>
java.lang.Object
dev.wyck.util.WeightedList<E>
A simple weighted random list.
Below FLAT_THRESHOLD total weight it uses a flat lookup array (O(1) draw, memory
proportional to total weight); at or above it, a linear scan (O(n) draw, O(n) memory).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final recordA value paired with its selection weight. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> WeightedList.Builder<E> builder()booleangetRandom(RandomGenerator random) getRandomOrThrow(RandomGenerator random) booleanisEmpty()static <E> WeightedList<E> of()static <E> WeightedList<E> of(WeightedList.Weighted<E>... items) static <E> WeightedList<E> of(E element) static <E> WeightedList<E> of(List<WeightedList.Weighted<E>> items) unwrap()
-
Method Details
-
of
-
of
-
of
-
of
-
builder
-
isEmpty
public boolean isEmpty() -
getRandom
-
getRandomOrThrow
-
unwrap
-
contains
-