public final class LongUtils extends Object
Modifier and Type | Method and Description |
---|---|
static LongCollection |
asLongCollection(Collection<Long> longs)
Get a Fastutil
LongCollection from a Collection of longs. |
static LongSet |
asLongSet(Set<Long> longs)
|
static LongSortedSet |
packedSet(Collection<Long> longs)
Pack longs into a sorted set.
|
static LongSortedSet |
packedSet(long... longs)
Pack longs into a sorted set.
|
static LongSortedSet |
randomSubset(LongSet set,
int num,
LongSet exclude,
Random rng)
Selects a random subset of
n longs from a given set of longs such that no selected
items is in a second set of longs. |
static LongSet |
randomSubset(LongSet set,
int num,
Random random)
Selects a random subset of
n longs from a given set of longs. |
static LongSortedSet |
setDifference(LongSet items,
LongSet exclude)
Compute the set difference of two sets.
|
static LongSortedSet |
setUnion(LongSortedSet a,
LongSortedSet b)
Compute the union of two sets.
|
static int |
unionSize(LongSortedSet a,
LongSortedSet b)
Compute the size of the union of two sets.
|
public static LongSortedSet packedSet(Collection<Long> longs)
longs
- A collection of longs.longs
.public static LongSortedSet packedSet(long... longs)
longs
- An array of longs. This array is copied, not wrapped.longs
.public static LongCollection asLongCollection(Collection<Long> longs)
LongCollection
from a Collection
of longs.
This method simply casts the collection, if possible, and returns a
wrapper otherwise.longs
- A collection of longs.LongCollection
.public static LongSet asLongSet(Set<Long> longs)
longs
- The set of longs.longs
as a fastutil LongSet
. If longs
is already
a LongSet, it is cast.public static LongSortedSet setDifference(LongSet items, LongSet exclude)
items
- The initial setexclude
- The items to removepublic static int unionSize(LongSortedSet a, LongSortedSet b)
a
- The first set.b
- The second set.public static LongSortedSet setUnion(LongSortedSet a, LongSortedSet b)
a
- The first set.b
- The second set.public static LongSet randomSubset(LongSet set, int num, Random random)
n
longs from a given set of longs. If fewer than n
items can be selected the whole set is returned.set
- the set of items to select fromnum
- The number of random items to add.random
- a random number generator to be used.base
plus an additional
nRandom
items.public static LongSortedSet randomSubset(LongSet set, int num, LongSet exclude, Random rng)
n
longs from a given set of longs such that no selected
items is in a second set of longs. If fewer than n
items can be selected the whole set is returned.set
- the set of items to select fromnum
- The number of random items to add.exclude
- a set of longs which must not be returnedrng
- a random number generator to be used.base
plus an additional
nRandom
items.