@Immutable public class LongSortedArraySet extends AbstractLongSortedSet implements java.io.Serializable
A sorted set of longs implemented using a sorted array. It’s much faster than LongArraySet
as it is able to use binary searches, while maintaining the space compactness of array-backed sets. Long sorted array sets are immutable.
No orders are supported other than the natural ordering.
Constructor and Description |
---|
LongSortedArraySet(java.util.Collection<java.lang.Long> items)
Construct a new array set from a collection of items.
|
LongSortedArraySet(long[] items)
Construct a new array set from an array of items.
|
LongSortedArraySet(SortedKeyIndex ks)
Construct a new long sorted array set from a key domain.
|
Modifier and Type | Method and Description |
---|---|
LongComparator |
comparator() |
boolean |
contains(long key) |
long |
firstLong() |
SortedKeyIndex |
getDomain()
Deprecated.
Use
getIndex() . |
SortedKeyIndex |
getIndex()
Get the underlying key index implementation.
|
LongSortedSet |
headSet(long key) |
LongBidirectionalIterator |
iterator() |
LongBidirectionalIterator |
iterator(long key) |
long |
lastLong() |
LongSortedSet |
randomSubset(java.util.Random rng,
int n,
LongSet... exclude)
Compute a random subset of this set.
|
int |
size() |
LongSortedSet |
subSet(long startKey,
long endKey) |
LongSortedSet |
tailSet(long key) |
equals, hashCode, rem, remove
add, add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toLongArray, toLongArray, toString
addAll, clear, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
first, headSet, last, subSet, tailSet
add, contains, rem, remove, remove
add, addAll, containsAll, removeAll, retainAll, toArray, toLongArray, toLongArray
forEach, forEach
public LongSortedArraySet(@Nonnull SortedKeyIndex ks)
Construct a new long sorted array set from a key domain.
ks
- The key set storage.public LongSortedArraySet(@Nonnull java.util.Collection<java.lang.Long> items)
Construct a new array set from a collection of items.
items
- The set’s contents.public LongSortedArraySet(long[] items)
Construct a new array set from an array of items.
items
- The items to initialize the set with. The items are copied, the array is not reused.public SortedKeyIndex getIndex()
Get the underlying key index implementation.
@Deprecated public SortedKeyIndex getDomain()
getIndex()
.Get the index backing this array set.
public LongComparator comparator()
comparator
in interface LongSortedSet
comparator
in interface java.util.SortedSet<java.lang.Long>
public long firstLong()
firstLong
in interface LongSortedSet
public long lastLong()
lastLong
in interface LongSortedSet
public LongBidirectionalIterator iterator()
iterator
in interface LongBidirectionalIterable
iterator
in interface LongCollection
iterator
in interface LongIterable
iterator
in interface LongSet
iterator
in interface LongSortedSet
iterator
in interface java.lang.Iterable<java.lang.Long>
iterator
in interface java.util.Collection<java.lang.Long>
iterator
in interface java.util.Set<java.lang.Long>
iterator
in class AbstractLongSortedSet
public LongBidirectionalIterator iterator(long key)
iterator
in interface LongSortedSet
public LongSortedSet subSet(long startKey, long endKey)
subSet
in interface LongSortedSet
public LongSortedSet headSet(long key)
headSet
in interface LongSortedSet
public LongSortedSet tailSet(long key)
tailSet
in interface LongSortedSet
public int size()
size
in interface java.util.Collection<java.lang.Long>
size
in interface java.util.Set<java.lang.Long>
size
in class java.util.AbstractCollection<java.lang.Long>
public boolean contains(long key)
contains
in interface LongCollection
contains
in class AbstractLongCollection
public LongSortedSet randomSubset(java.util.Random rng, int n, LongSet... exclude)
Compute a random subset of this set.
n
- The desired set size.exclude
- One or more sets of items to exclude.exclude
.