public abstract class LongKeyDomain extends Object implements Serializable
LongSortedArraySet
, SparseVector
, etc.
This class should not be directly used outside of the LensKit data structures.
A key set has a domain, which is the set of all possible keys that it can contain. These keys are stored in an array. The active keys are those that are actually in the set. Active/inactive status is tracked with a bitmask.
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Mark the key set as owned, but don't copy it.
|
LongKeyDomain |
activate(BitSet active)
Activate bits from a bit set.
|
IntBidirectionalIterator |
activeIndexIterator(boolean mayBeModified)
Get an iterator over active indexes.
|
IntBidirectionalIterator |
activeIndexIterator(int min,
int max,
int idx)
Get an iterator over active indexes, initialized to the specified index and limited to a
particular range.
|
LongSortedSet |
activeSetView()
Get a vew of this key set as a set.
|
LongKeyDomain |
clone()
Return a copy of this key set.
|
LongKeyDomain |
compactCopy()
Make a compact copy of this key set.
|
LongKeyDomain |
compactCopy(boolean active)
Make a compact copy of this key set.
|
boolean |
containsKey(long key)
Query whether this set contains the specified key in its domain.
|
static LongKeyDomain |
create(long... keys)
Create a key set with some keys.
|
LongSortedSet |
domain()
Get the key set's domain as a set.
|
int |
domainSize()
Get the domain size of this set.
|
static LongKeyDomain |
empty()
Create an empty key domain.
|
static LongKeyDomain |
fromCollection(Collection<Long> keys)
Create a key set from a collection of keys.
|
static LongKeyDomain |
fromCollection(Collection<Long> keys,
boolean initiallyActive)
Create a key set from a collection of keys.
|
BitSet |
getActiveMask()
Get the active keys as a bit set.
|
abstract int |
getIndex(long key)
Get the index for a key, regardless of its active state.
|
int |
getIndexIfActive(long key)
Get the index for a key if that key is active.
|
abstract long |
getKey(int idx)
Get the key at an index.
|
LongKeyDomain |
inactiveCopy()
Return a copy of this key set that is entirely inactive.
|
boolean |
indexIsActive(int idx)
Query whether an index is active.
|
LongKeyDomain |
invert()
Invert the active status of all keys in the set.
|
abstract boolean |
isCompatibleWith(LongKeyDomain other)
Query whether this key set is compatible with another.
|
boolean |
isCompletelySet()
Query whether this domain is completely set (has no unset keys).
|
boolean |
keyIsActive(long key)
Query whether a key is active.
|
LongBidirectionalIterator |
keyIterator(IntBidirectionalIterator iter)
Wrap an index iterator into a key iterator.
|
LongList |
keyList()
Get the key set's list of keys (domain) as a list.
|
int |
lowerBound(long key)
Get the lower bound, the first index whose key is greater than or equal to the specified key.
|
LongSortedSet |
modifiableActiveSetView()
Get a view of this key set as a set that supports limited mutation.
|
LongKeyDomain |
setActive(BitSet active)
Set the active bits from a bit set.
|
LongKeyDomain |
setActive(int idx,
boolean active)
Set the active flag for a single key.
|
LongKeyDomain |
setAllActive(boolean active)
Set the active status of all entries in the key set.
|
int |
size()
Get the number of active keys in this set.
|
LongKeyDomain |
unowned()
Mark this key set as unowned.
|
int |
upperBound(long key)
Get the upper bound, the first index whose key is greater than the specified key.
|
static LongKeyDomain |
wrap(long[] keys,
int size,
boolean initiallyActive)
Wrap a key array (with a specified size) into a key set.
|
public static LongKeyDomain wrap(long[] keys, int size, boolean initiallyActive)
keys
- The key array. This array must be sorted, and must not contain duplicates. For
efficiency, this condition is not checked unless assertions are enabled. Since
this method is only intended to be used when implementing test cases or other
data structures, callers of this method should ensure sortedness and
throw the appropriate exception.size
- The length of the array to actually use.initiallyActive
- true
to activate all keys initially, false
to leave
them inactive.public static LongKeyDomain fromCollection(Collection<Long> keys, boolean initiallyActive)
keys
- The key collection.initiallyActive
- true
if the elements of the key set should be initially
activated; false
to make all keys initially inactive.public static LongKeyDomain fromCollection(Collection<Long> keys)
keys
- The keys.public static LongKeyDomain create(long... keys)
keys
- The keys.public static LongKeyDomain empty()
public abstract int getIndex(long key)
key
- The key.Arrays.binarySearch(long[], int, int, long)
.public int getIndexIfActive(long key)
key
- The key.public int upperBound(long key)
key
- The key to search for.domainSize()
if the key
is the last key in the domain. The index is not necessarily active.public int lowerBound(long key)
upperBound(long)
; the interval
[lowerBound(k),upperBound(k))
contains the index of k
, if the key is in the
domain, and is empty if the key is not in the domain.key
- The key to search for.key
.public LongKeyDomain clone()
public LongKeyDomain unowned()
clone()
will mark the
key set as owned and return it rather than making a copy. This allows code to avoid an
extra copy when creating a key set to pass off to another method or object that will make
a defensive copy.
You almost certainly do not want to call this method.
Any object or method that receives a key set that it intends to take ownership of must
call clone()
to make sure that it owns the set.
public void acquire()
public LongKeyDomain inactiveCopy()
public LongKeyDomain compactCopy()
public LongKeyDomain compactCopy(boolean active)
active
- Whether the keys should be active or inactive in the compacted key set.public boolean indexIsActive(int idx)
idx
- The index.true
if the key at the index is active.public boolean keyIsActive(long key)
key
- The key to query.true
if the key is in the domain and active.public boolean containsKey(long key)
key
- The key.true
if the key is in the domain.public abstract long getKey(int idx)
idx
- The index to query.public int domainSize()
public int size()
public boolean isCompletelySet()
true
if the domain is completely set.public IntBidirectionalIterator activeIndexIterator(boolean mayBeModified)
mayBeModified
- Whether the set's active/inactive flags may be modified during iteration.
If false
, this method is slightly more efficient; if true
,
the iterator will iterate over a snapshot of the current active/inactive
state.public IntBidirectionalIterator activeIndexIterator(int min, int max, int idx)
min
- The minimum index for the iterator.max
- The maximum index for the iterator.idx
- The starting index for the iterator. The iterator can go backwards from this
index, if it is greater than min
.public LongBidirectionalIterator keyIterator(IntBidirectionalIterator iter)
iter
- The index iterator.public LongSortedSet activeSetView()
public LongSortedSet modifiableActiveSetView()
remove(Object)
, rem(long)
,
removeAll(Collection)
, and retainAll(Collection)
), and those removals will
be reflected by marking the associated entries as inactive in the key set.activeSetView()
public LongSortedSet domain()
public LongList keyList()
public BitSet getActiveMask()
public abstract boolean isCompatibleWith(@Nonnull LongKeyDomain other)
clone()
are compatible with their parent and
each other.other
- The other key set.true
if the two key sets are compatible.public LongKeyDomain invert()
this
(for chaining).public LongKeyDomain setAllActive(boolean active)
active
- true
to activate, false
to deactivate.public LongKeyDomain setActive(int idx, boolean active)
idx
- The key's index.active
- Whether the key is active.public LongKeyDomain setActive(BitSet active)
active
- The bits to set. Unset bits in this set are cleared.public LongKeyDomain activate(BitSet active)
active
- The bits to set. Unset bits in this set are left unchanged.