public class ImmutableBitSet extends Object implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet>
| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableBitSet.Builder
Builder.
|
private static class |
ImmutableBitSet.Closure
Setup equivalence Sets for each position.
|
private static class |
ImmutableBitSet.Rebuilder
Refinement of
ImmutableBitSet.Builder that remembers its original
ImmutableBitSet and tries to use it
when ImmutableBitSet.Rebuilder.build() is called. |
| Modifier and Type | Field and Description |
|---|---|
private static int |
ADDRESS_BITS_PER_WORD |
private static int |
BITS_PER_WORD |
static Comparator<ImmutableBitSet> |
COMPARATOR
Compares bit sets topologically, so that enclosing bit sets come first,
using natural ordering to break ties.
|
private static ImmutableBitSet |
EMPTY |
private static long[] |
EMPTY_LONGS |
static com.google.common.base.Function<? super BitSet,ImmutableBitSet> |
FROM_BIT_SET |
static com.google.common.collect.Ordering<ImmutableBitSet> |
ORDERING |
private static long |
WORD_MASK |
private long[] |
words |
| Modifier | Constructor and Description |
|---|---|
private |
ImmutableBitSet(long[] words)
Private constructor.
|
| Modifier and Type | Method and Description |
|---|---|
List<Integer> |
asList()
Creates a view onto this bit set as a list of integers.
|
Set<Integer> |
asSet()
Creates a view onto this bit set as a set of integers.
|
static ImmutableBitSet.Builder |
builder()
Creates an empty Builder.
|
static ImmutableBitSet.Builder |
builder(ImmutableBitSet bitSet)
Deprecated.
|
int |
cardinality()
Returns the number of bits set to
true in this
ImmutableBitSet. |
private static void |
checkRange(int fromIndex,
int toIndex)
Checks that fromIndex ...
|
ImmutableBitSet |
clear(int i)
Returns a bit set the same as this but with a given bit cleared.
|
ImmutableBitSet |
clearIf(int i,
boolean condition)
Returns a bit set the same as this but with a given bit cleared if
condition is true.
|
static SortedMap<Integer,ImmutableBitSet> |
closure(SortedMap<Integer,ImmutableBitSet> equivalence)
Computes the closure of a map from integers to bits.
|
int |
compareTo(ImmutableBitSet o)
Compares this ImmutableBitSet with another, using a lexicographic
ordering.
|
boolean |
contains(ImmutableBitSet set1)
Returns true if all bits set in the second parameter are also set in the
first.
|
private static int |
countBits(long[] words) |
boolean |
equals(Object obj)
Compares this object against the specified object.
|
ImmutableBitSet |
except(ImmutableBitSet that)
Returns a bit set with all the bits in this set that are not in
another.
|
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index.
|
ImmutableBitSet |
get(int fromIndex,
int toIndex)
Returns a new
ImmutableBitSet
composed of bits from this ImmutableBitSet
from fromIndex (inclusive) to toIndex (exclusive). |
int |
hashCode()
Returns the hash code value for this bit set.
|
int |
indexOf(int bit)
The ordinal of a given bit, or -1 if it is not set.
|
ImmutableBitSet |
intersect(ImmutableBitSet that)
Returns a bit set with all the bits set in both this set and in
another.
|
boolean |
intersects(ImmutableBitSet set)
Returns true if the specified
ImmutableBitSet has any bits set to
true that are also set to true in this
ImmutableBitSet. |
boolean |
isEmpty()
Returns true if this
ImmutableBitSet contains no bits that are set
to true. |
Iterator<Integer> |
iterator() |
int |
length()
Returns the "logical size" of this
ImmutableBitSet: the index of
the highest set bit in the ImmutableBitSet plus one. |
int |
nextClearBit(int fromIndex)
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index. |
int |
nextSetBit(int fromIndex)
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. |
int |
nth(int n)
Returns the
nth set bit. |
static ImmutableBitSet |
of()
Creates an ImmutableBitSet with no bits.
|
static ImmutableBitSet |
of(ImmutableIntList bits)
Creates an ImmutableBitSet with given bits set.
|
static ImmutableBitSet |
of(int... bits) |
static ImmutableBitSet |
of(Iterable<Integer> bits) |
static Iterable<ImmutableBitSet> |
permute(Iterable<ImmutableBitSet> bitSets,
Map<Integer,Integer> map)
Permutes a collection of bit sets according to a given mapping.
|
ImmutableBitSet |
permute(Map<Integer,Integer> map)
Permutes a bit set according to a given mapping.
|
Iterable<ImmutableBitSet> |
powerSet()
Computes the power set (set of all sets) of this bit set.
|
int |
previousClearBit(int fromIndex)
Returns the index of the nearest bit that is set to
false
that occurs on or before the specified starting index. |
static ImmutableBitSet |
range(int toIndex)
Creates an ImmutableBitSet with bits between 0 and
toIndex set. |
static ImmutableBitSet |
range(int fromIndex,
int toIndex)
Creates an ImmutableBitSet with bits from
fromIndex (inclusive) to
specified toIndex (exclusive) set to true. |
ImmutableBitSet.Builder |
rebuild()
Creates a Builder whose initial contents are the same as this
ImmutableBitSet.
|
ImmutableBitSet |
set(int i)
Returns a bit set the same as this but with a given bit set.
|
ImmutableBitSet |
set(int i,
boolean b)
Returns a bit set the same as this but with a given bit set (if b is
true) or unset (if b is false).
|
ImmutableBitSet |
setIf(int bit,
boolean condition)
Returns a bit set the same as this but with a given bit set if condition
is true.
|
ImmutableBitSet |
shift(int offset)
Returns a bit set with every bit moved up
offset positions. |
int |
size()
Returns the number of bits of space actually in use by this
ImmutableBitSet to represent bit values. |
int[] |
toArray()
Converts this bit set to an array.
|
BitSet |
toBitSet()
Returns a
BitSet that has the same contents as this
ImmutableBitSet. |
List<Integer> |
toList()
Converts this bit set to a list.
|
long[] |
toLongArray()
Converts this bit set to an array of little-endian words.
|
String |
toString()
Returns a string representation of this bit set.
|
ImmutableBitSet |
union(BitSet other)
Returns the union of this immutable bit set with a
BitSet. |
ImmutableBitSet |
union(ImmutableBitSet other)
Returns the union of this bit set with another.
|
static ImmutableBitSet |
union(Iterable<? extends ImmutableBitSet> sets)
Returns the union of a number of bit sets.
|
static ImmutableBitSet |
valueOf(long... longs)
Returns a new immutable bit set containing all the bits in the given long
array.
|
static ImmutableBitSet |
valueOf(LongBuffer longs)
Returns a new immutable bit set containing all the bits in the given long
buffer.
|
private static int |
wordIndex(int bitIndex)
Given a bit index, return word index containing it.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static final Comparator<ImmutableBitSet> COMPARATOR
public static final com.google.common.collect.Ordering<ImmutableBitSet> ORDERING
private static final int ADDRESS_BITS_PER_WORD
private static final int BITS_PER_WORD
private static final long WORD_MASK
private static final long[] EMPTY_LONGS
private static final ImmutableBitSet EMPTY
public static final com.google.common.base.Function<? super BitSet,ImmutableBitSet> FROM_BIT_SET
private final long[] words
private ImmutableBitSet(long[] words)
public static ImmutableBitSet of()
public static ImmutableBitSet of(int... bits)
public static ImmutableBitSet of(Iterable<Integer> bits)
public static ImmutableBitSet of(ImmutableIntList bits)
For example, of(ImmutableIntList.of(0, 3)) returns a bit
set with bits {0, 3} set.
bits - Collection of bits to setpublic static ImmutableBitSet valueOf(long... longs)
More precisely,
ImmutableBitSet.valueOf(longs).get(n)
== ((longs[n/64] & (1L<<(n%64))) != 0)
for all n < 64 * longs.length.
This method is equivalent to
ImmutableBitSet.valueOf(LongBuffer.wrap(longs)).
longs - a long array containing a little-endian representation
of a sequence of bits to be used as the initial bits of the
new bit setImmutableBitSet containing all the bits in the long
arraypublic static ImmutableBitSet valueOf(LongBuffer longs)
public static ImmutableBitSet range(int fromIndex, int toIndex)
fromIndex (inclusive) to
specified toIndex (exclusive) set to true.
For example, range(0, 3) returns a bit set with bits
{0, 1, 2} set.
fromIndex - Index of the first bit to be set.toIndex - Index after the last bit to be set.public static ImmutableBitSet range(int toIndex)
toIndex set.private static int wordIndex(int bitIndex)
public Iterable<ImmutableBitSet> powerSet()
public boolean get(int bitIndex)
true if the bit with the index bitIndex
is currently set in this ImmutableBitSet; otherwise, the result
is false.bitIndex - the bit indexIndexOutOfBoundsException - if the specified index is negativepublic ImmutableBitSet get(int fromIndex, int toIndex)
ImmutableBitSet
composed of bits from this ImmutableBitSet
from fromIndex (inclusive) to toIndex (exclusive).fromIndex - index of the first bit to includetoIndex - index after the last bit to includeImmutableBitSet from a range of
this ImmutableBitSetIndexOutOfBoundsException - if fromIndex is negative,
or toIndex is negative, or fromIndex is
larger than toIndexprivate static void checkRange(int fromIndex,
int toIndex)
public String toString()
BitSet contains a bit in the set
state, the decimal representation of that index is included in
the result. Such indices are listed in order from lowest to
highest, separated by ", " (a comma and a space) and
surrounded by braces, resulting in the usual mathematical
notation for a set of integers.
Example:
BitSet drPepper = new BitSet();Now
drPepper.toString() returns "{}".
drPepper.set(2);Now
drPepper.toString() returns "{2}".
drPepper.set(4); drPepper.set(10);Now
drPepper.toString() returns "{2, 4, 10}".public boolean intersects(ImmutableBitSet set)
ImmutableBitSet has any bits set to
true that are also set to true in this
ImmutableBitSet.set - ImmutableBitSet to intersect withImmutableBitSet intersects
the specified ImmutableBitSetpublic int cardinality()
true in this
ImmutableBitSet.size()private static int countBits(long[] words)
public int hashCode()
ImmutableBitSet.
The hash code is defined using the same calculation as
BitSet.hashCode().
public int size()
ImmutableBitSet to represent bit values.
The maximum element in the set is the size - 1st element.cardinality()public boolean equals(Object obj)
true if and only if the argument is
not null and is a ImmutableBitSet object that has
exactly the same set of bits set to true as this bit
set.public int compareTo(ImmutableBitSet o)
Bit sets (), (0), (0, 1), (0, 1, 3), (1), (2, 3) are in sorted
order.
compareTo in interface Comparable<ImmutableBitSet>public int nextSetBit(int fromIndex)
true
that occurs on or after the specified starting index. If no such
bit exists then -1 is returned.
Based upon BitSet.nextSetBit(int).
fromIndex - the index to start checking from (inclusive)-1 if there
is no such bitIndexOutOfBoundsException - if the specified index is negativepublic int nextClearBit(int fromIndex)
false
that occurs on or after the specified starting index.fromIndex - the index to start checking from (inclusive)IndexOutOfBoundsException - if the specified index is negativepublic int previousClearBit(int fromIndex)
false
that occurs on or before the specified starting index.
If no such bit exists, or if -1 is given as the
starting index, then -1 is returned.fromIndex - the index to start checking from (inclusive)-1 if there
is no such bitIndexOutOfBoundsException - if the specified index is less
than -1public List<Integer> asList()
The cardinality and get methods are both O(n), but
the iterator is efficient. The list is memory efficient, and the CPU cost
breaks even (versus toList()) if you intend to scan it only once.
public Set<Integer> asSet()
The size and contains methods are both O(n), but the
iterator is efficient.
public int[] toArray()
Each entry of the array is the ordinal of a set bit. The array is sorted.
public long[] toLongArray()
public ImmutableBitSet union(BitSet other)
BitSet.public ImmutableBitSet union(ImmutableBitSet other)
public static ImmutableBitSet union(Iterable<? extends ImmutableBitSet> sets)
public ImmutableBitSet except(ImmutableBitSet that)
BitSet.andNot(java.util.BitSet)public ImmutableBitSet intersect(ImmutableBitSet that)
BitSet.and(java.util.BitSet)public boolean contains(ImmutableBitSet set1)
set1 - Bitmap to be checkedpublic int indexOf(int bit)
public static SortedMap<Integer,ImmutableBitSet> closure(SortedMap<Integer,ImmutableBitSet> equivalence)
The input must have an entry for each position.
Does not modify the input map or its bit sets.
public int length()
ImmutableBitSet: the index of
the highest set bit in the ImmutableBitSet plus one. Returns zero
if the ImmutableBitSet contains no set bits.ImmutableBitSetpublic boolean isEmpty()
ImmutableBitSet contains no bits that are set
to true.public static ImmutableBitSet.Builder builder()
@Deprecated public static ImmutableBitSet.Builder builder(ImmutableBitSet bitSet)
public ImmutableBitSet.Builder rebuild()
public int nth(int n)
nth set bit.IndexOutOfBoundsException - if n is less than 0 or greater
than the number of bits setpublic ImmutableBitSet set(int i)
public ImmutableBitSet set(int i, boolean b)
public ImmutableBitSet setIf(int bit, boolean condition)
public ImmutableBitSet clear(int i)
public ImmutableBitSet clearIf(int i, boolean condition)
public BitSet toBitSet()
BitSet that has the same contents as this
ImmutableBitSet.public ImmutableBitSet permute(Map<Integer,Integer> map)
public static Iterable<ImmutableBitSet> permute(Iterable<ImmutableBitSet> bitSets, Map<Integer,Integer> map)
public ImmutableBitSet shift(int offset)
offset positions.
Offset may be negative, but throws if any bit ends up negative.Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.