public class ImmutableBitSet extends Object implements Iterable<Integer>, Serializable, Comparable<ImmutableBitSet>
| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableBitSet.Builder
Builder.
|
| Modifier and Type | Field and Description |
|---|---|
static Comparator<ImmutableBitSet> |
COMPARATOR
Compares bit sets topologically, so that enclosing bit sets come first,
using natural ordering to break ties.
|
static com.google.common.base.Function<? super BitSet,ImmutableBitSet> |
FROM_BIT_SET |
static com.google.common.collect.Ordering<ImmutableBitSet> |
ORDERING |
| Modifier and Type | Method and Description |
|---|---|
List<Integer> |
asList()
Creates a view onto this bit set as a list of integers.
|
static ImmutableBitSet.Builder |
builder() |
static ImmutableBitSet.Builder |
builder(ImmutableBitSet bitSet) |
int |
cardinality()
Returns the number of bits set to
true in this
ImmutableBitSet. |
ImmutableBitSet |
clear(int i)
Returns a bit set the same as this but with a given bit cleared.
|
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.
|
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.
|
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) |
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 |
set(int i)
Returns a bit set the same as this but with a given bit set.
|
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. |
IntList |
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(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.
|
public static final Comparator<ImmutableBitSet> COMPARATOR
public static final com.google.common.collect.Ordering<ImmutableBitSet> ORDERING
public static final com.google.common.base.Function<? super BitSet,ImmutableBitSet> FROM_BIT_SET
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.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 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.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.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 IntList toList()
public 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 int[] toArray()
Each entry of the array is the ordinal of a set bit. The array is sorted.
public long[] toLongArray()
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()
public static ImmutableBitSet.Builder builder(ImmutableBitSet bitSet)
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 clear(int i)
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.