@ParametersAreNonnullByDefault
public final class LongUtils
extends java.lang.Object
Utilities for working with longs and collections of them from Fastutil.
| Modifier and Type | Method and Description |
|---|---|
static Long2DoubleMap |
asLong2DoubleFunction(java.util.Map<java.lang.Long,java.lang.Double> map)
Deprecated.
|
static Long2DoubleMap |
asLong2DoubleMap(java.util.Map<java.lang.Long,java.lang.Double> map)
Wrap or cast a long-to-double map into Fastutil.
|
static LongCollection |
asLongCollection(java.util.Collection<java.lang.Long> longs)
Get a Fastutil
LongCollection from a Collection of longs. |
static LongList |
asLongList(java.util.List<java.lang.Long> longs) |
static LongSet |
asLongSet(java.util.Collection<java.lang.Long> longs)
Get a Fastutil
LongSet from a Collection of longs. |
static LongSet |
asLongSet(java.util.Set<java.lang.Long> longs)
Get a Fastutil
LongSet from a Set of longs. |
static Long2DoubleMap |
constantDoubleMap(java.util.Set<java.lang.Long> keys,
double value)
Create a map that maps a group of items to the same value.
|
static Long2DoubleMap |
flyweightMap(LongSet keys,
java.util.function.LongToDoubleFunction valueFunc)
Create a flyweight vector with a key set and value function.
|
static Long2DoubleSortedMap |
frozenMap(java.util.Map<java.lang.Long,java.lang.Double> map)
Create a frozen long-to-double map.
|
static LongSortedSet |
frozenSet(java.util.Collection<java.lang.Long> longs)
Create a frozen long set.
|
static boolean |
hasNCommonItems(LongSortedSet a,
LongSortedSet b,
int n)
Check if two sets have at least a given number of common items.
|
static int |
intersectSize(LongSet a,
LongSet b)
Compute the size of the intersection of two sets.
|
static int |
intersectSize(LongSortedSet a,
LongSortedSet b)
Compute the size of the intersection of two sets.
|
static Long2IntMap |
itemRanks(LongList results)
Compute the ranks for a list of longs.
|
static LongComparator |
keyValueComparator(Long2DoubleFunction vals)
Create a comparator that compares long keys by associated double values.
|
static <T,E> java.util.stream.Collector<T,?,Long2ObjectMap<java.util.List<E>>> |
mapCollector(java.util.function.ToLongFunction<T> kf,
java.util.function.Function<T,E> vf) |
static LongSortedArraySet |
packedSet(java.util.Collection<java.lang.Long> longs)
Pack longs into a sorted set.
|
static LongSortedArraySet |
packedSet(long... longs)
Pack longs into a sorted set.
|
static LongSortedSet |
randomSubset(LongSet set,
int num,
LongSet exclude,
java.util.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,
java.util.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 |
setIntersect(LongSet a,
LongSet b)
Compute the intersection of two sets.
|
static LongSortedSet |
setIntersect(LongSortedSet a,
LongSortedSet b)
Compute the intersection of two sets.
|
static LongSortedSet |
setUnion(LongSet a,
LongSet b)
Compute the union 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 Long2DoubleSortedMap frozenMap(java.util.Map<java.lang.Long,java.lang.Double> map)
Create a frozen long-to-double map. This effectively creates a copy of a map, but if the provided map is an instance of Long2DoubleSortedArrayMap, which is immutable, it is returned as-is for efficiency.
map - The source map.map.public static LongSortedSet frozenSet(java.util.Collection<java.lang.Long> longs)
Create a frozen long set. If the underlying collection is already an immutable sorted set (specifically, a LongSortedArraySet, it is used as-is. Otherwise, it is copied into a sorted array set.
This is equivalent to packedSet(Collection).
longs - The collection.packedSet(Collection)public static LongSortedArraySet packedSet(java.util.Collection<java.lang.Long> longs)
Pack longs into a sorted set.
longs - A collection of longs.longs.public static LongSortedArraySet packedSet(long... longs)
Pack longs into a sorted set.
longs - An array of longs. This array is copied, not wrapped.longs.public static LongComparator keyValueComparator(Long2DoubleFunction vals)
Create a comparator that compares long keys by associated double values.
vals - The value map.public static Long2DoubleMap flyweightMap(LongSet keys, java.util.function.LongToDoubleFunction valueFunc)
Create a flyweight vector with a key set and value function.
keys - The key set.valueFunc - Function to compute keys from values.public static LongCollection asLongCollection(java.util.Collection<java.lang.Long> longs)
Get a Fastutil 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 Long2DoubleMap asLong2DoubleMap(java.util.Map<java.lang.Long,java.lang.Double> map)
Wrap or cast a long-to-double map into Fastutil.
map - The map.map, or map if it is a Fastutil map.@Deprecated public static Long2DoubleMap asLong2DoubleFunction(java.util.Map<java.lang.Long,java.lang.Double> map)
asLong2DoubleMap(Map)Create a long-to-double function from a map, casting if appropriate. Useful to allow unboxed access to maps that are really fastutil maps.
map - The map.map, or map if it is a Fastutil map.public static LongList asLongList(java.util.List<java.lang.Long> longs)
public static Long2DoubleMap constantDoubleMap(java.util.Set<java.lang.Long> keys, double value)
Create a map that maps a group of items to the same value.
keys - The keys.value - The value.keys, mapping each of them to value.public static LongSet asLongSet(@Nullable java.util.Set<java.lang.Long> longs)
Get a Fastutil LongSet from a Set of longs.
longs - The set of longs.longs as a fastutil LongSet. If longs is already a LongSet, it is cast.public static LongSet asLongSet(@Nullable java.util.Collection<java.lang.Long> longs)
Get a Fastutil LongSet from a Collection of longs.
longs - The set of longs.longs as a fastutil LongSet. If longs is already a LongSet, it is cast.public static Long2IntMap itemRanks(LongList results)
Compute the ranks for a list of longs.
results - The list of longs.public static LongSortedSet setDifference(LongSet items, LongSet exclude)
Compute the set difference of two sets.
items - The initial setexclude - The items to removepublic static int intersectSize(LongSortedSet a, LongSortedSet b)
Compute the size of the intersection of two sets.
a - The first set.b - The second set.public static int intersectSize(LongSet a, LongSet b)
Compute the size of the intersection of two sets.
a - The first set.b - The second set.public static boolean hasNCommonItems(LongSortedSet a, LongSortedSet b, int n)
Check if two sets have at least a given number of common items.
a - The first set.b - The second set.n - The number of common items to require.true if the two sets have at least n common items.public static int unionSize(LongSortedSet a, LongSortedSet b)
Compute the size of the union of two sets.
a - The first set.b - The second set.public static LongSortedSet setUnion(LongSet a, LongSet b)
Compute the union of two sets.
a - The first set.b - The second set.public static LongSortedSet setUnion(LongSortedSet a, LongSortedSet b)
Compute the union of two sets.
a - The first set.b - The second set.public static LongSortedSet setIntersect(LongSet a, LongSet b)
Compute the intersection of two sets.
a - The first set.b - The second set.public static LongSortedSet setIntersect(LongSortedSet a, LongSortedSet b)
Compute the intersection of two sets.
a - The first set.b - The second set.public static LongSet randomSubset(LongSet set, int num, java.util.Random random)
Selects a random subset of 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, java.util.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. 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.public static <T,E> java.util.stream.Collector<T,?,Long2ObjectMap<java.util.List<E>>> mapCollector(java.util.function.ToLongFunction<T> kf, java.util.function.Function<T,E> vf)