Package mondrian.rolap
Interface BitKey
-
- All Superinterfaces:
Comparable<BitKey>
,Iterable<Integer>
,Serializable
- All Known Implementing Classes:
BitKey.AbstractBitKey
,BitKey.Big
,BitKey.Mid128
,BitKey.Small
public interface BitKey extends Serializable, Comparable<BitKey>, Iterable<Integer>
Represents a set of bits.Unlike
BitSet
, the number of bits cannot be changed after the BitKey is created. This allows us to optimize.If you have a collection of immutable objects, each of which has a unique positive number and you wish to do comparisons between subsets of those objects testing for equality, then encoding the subsets as BitKeys is very efficient.
There are two implementations that target groups of objects with maximum number less than 64 and less than 128; and there is one implements that is general for any positive number.
One caution: if the maximum number assigned to one of the objects is large, then this representation might be sparse and therefore not efficient.
- Author:
- Richard M. Emberson
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
BitKey.AbstractBitKey
Abstract implementation ofBitKey
.static class
BitKey.Big
Implementation ofBitKey
with more than 64 bits.static class
BitKey.Factory
static class
BitKey.Mid128
Implementation ofBitKey
good for sizes less than 128.static class
BitKey.Small
Implementation ofBitKey
for bit counts less than 64.
-
Field Summary
Fields Modifier and Type Field Description static byte[]
bitPositionTable
static BitKey
EMPTY
The BitKey with no bits set.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BitKey
and(BitKey bitKey)
Returns the boolean AND of this bitkey and the given bitkey.BitKey
andNot(BitKey bitKey)
Returns aBitKey
containing all of the bits in thisBitSet
whose corresponding bit is NOT set in the specifiedBitSet
.int
cardinality()
Returns the number of bits set.void
clear()
Sets all of the bits in this BitKey tofalse
.void
clear(int bitIndex)
Sets the bit specified by the index tofalse
.BitKey
copy()
Returns a copy of this BitKey.BitKey
emptyCopy()
Returns an empty BitKey of the same type.boolean
get(int bitIndex)
Returns the value of the bit with the specified index.boolean
intersects(BitKey bitKey)
Returns whether this BitKey has any bits in common with a given BitKey.boolean
isEmpty()
Returns true if thisBitKey
contains no bits that are set totrue
.boolean
isSuperSetOf(BitKey bitKey)
Is every bit set in the parameterbitKey
also set inthis
.Iterator<Integer>
iterator()
An Iterator over the bit positions.int
nextSetBit(int fromIndex)
Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index.BitKey
or(BitKey bitKey)
Or the parameterBitKey
withthis
.BitKey
orNot(BitKey bitKey)
XOr the parameterBitKey
withthis
.void
set(int bitIndex)
Sets the bit at the specified index totrue
.void
set(int bitIndex, boolean value)
Sets the bit at the specified index to the specified value.BitSet
toBitSet()
Returns aBitSet
with the same contents as this BitKey.-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
EMPTY
static final BitKey EMPTY
The BitKey with no bits set.
-
bitPositionTable
static final byte[] bitPositionTable
-
-
Method Detail
-
set
void set(int bitIndex, boolean value)
Sets the bit at the specified index to the specified value.
-
set
void set(int bitIndex)
Sets the bit at the specified index totrue
.
-
get
boolean get(int bitIndex)
Returns the value of the bit with the specified index. The value istrue
if the bit with the indexbitIndex
is currently set in thisBitKey
; otherwise, the result isfalse
.
-
clear
void clear(int bitIndex)
Sets the bit specified by the index tofalse
.
-
clear
void clear()
Sets all of the bits in this BitKey tofalse
.
-
isSuperSetOf
boolean isSuperSetOf(BitKey bitKey)
Is every bit set in the parameterbitKey
also set inthis
. If one switchesthis
with the parameterbitKey
one gets the equivalent of isSubSetOf.- Parameters:
bitKey
- Bit key
-
and
BitKey and(BitKey bitKey)
Returns the boolean AND of this bitkey and the given bitkey.- Parameters:
bitKey
- Bit key
-
andNot
BitKey andNot(BitKey bitKey)
Returns aBitKey
containing all of the bits in thisBitSet
whose corresponding bit is NOT set in the specifiedBitSet
.
-
copy
BitKey copy()
Returns a copy of this BitKey.- Returns:
- copy of BitKey
-
emptyCopy
BitKey emptyCopy()
- Returns:
- BitKey of same type
-
isEmpty
boolean isEmpty()
Returns true if thisBitKey
contains no bits that are set totrue
.
-
intersects
boolean intersects(BitKey bitKey)
Returns whether this BitKey has any bits in common with a given BitKey.
-
iterator
Iterator<Integer> iterator()
An Iterator over the bit positions. For example, if the BitKey had positions 3 and 4 set, then the Iterator would return the values 3 and then 4. The bit positions returned by the iterator are in the order, from smallest to largest, as they are set in the BitKey.
-
nextSetBit
int nextSetBit(int fromIndex)
Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index. If no such bit exists then -1 is returned. To iterate over thetrue
bits in aBitKey
, use the following loop:for (int i = bk.nextSetBit(0); i >= 0; i = bk.nextSetBit(i + 1)) { // operate on index i here }
- Parameters:
fromIndex
- the index to start checking from (inclusive)- Returns:
- the index of the next set bit
- Throws:
IndexOutOfBoundsException
- if the specified index is negative
-
cardinality
int cardinality()
Returns the number of bits set.- Returns:
- Number of bits set
-
-