Package org.apache.lucene.util

# Class SparseFixedBitSet

java.lang.Object
org.apache.lucene.util.BitSet
org.apache.lucene.util.SparseFixedBitSet

All Implemented Interfaces:
  `Accountable`, `Bits`

public class SparseFixedBitSet extends BitSet
A bit set that only stores longs that have at least one bit which is set. The way it works is that the space of bits is divided into blocks of 4096 bits, which is 64 longs. Then for each block, we have:

- a long[] which stores the non-zero longs for that block
- a long so that bit `i` being set means that the `i-th` long of the block is non-null, and its offset in the array of longs is the number of one bits on the right of the `i-th` bit.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.apache.lucene.util.Bits

`Bits.MatchAllBits, Bits.MatchNoBits`

## Field Summary

### Fields inherited from interface org.apache.lucene.util.Accountable

`NULL_ACCOUNTABLE`

### Fields inherited from interface org.apache.lucene.util.Bits

`EMPTY_ARRAY`

## Constructor Summary

Constructors
Constructor
Description
`SparseFixedBitSet(int length)`
Create a `SparseFixedBitSet` that can contain bits between `0` included and `length` excluded.

## Method Summary

Modifier and Type
Method
Description
`int`
`approximateCardinality()`
Return an approximation of the cardinality of this set.
`int`
`cardinality()`
Return the number of bits that are set.
`void`
`clear()`
Clear all the bits of the set.
`void`
`clear(int i)`
Clear the bit at index `i`.
`void`
`clear(int from, int to)`
Clears a range of bits.
`boolean`
`get(int i)`
Returns the value of the bit with the specified `index`.
`boolean`
`getAndSet(int i)`
Set the bit at `i`, returning `true` if it was previously set.
`int`
`length()`
Returns the number of bits in this set
`int`
`nextSetBit(int i)`
Returns the index of the first set bit starting at the index specified.
`int`
`nextSetBit(int start, int upperBound)`
Returns the index of the first set bit from start (inclusive) until end (exclusive).
`void`
`or(DocIdSetIterator it)`
Does in-place OR of the bits provided by the iterator.
`int`
`prevSetBit(int i)`
Returns the index of the last set bit before or on the index specified.
`long`
`ramBytesUsed()`
Return the memory usage of this object in bytes.
`void`
`set(int i)`
Set the bit at index `i`.
`String`
`toString()`

### Methods inherited from class org.apache.lucene.util.BitSet

`checkUnpositioned, of`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.apache.lucene.util.Accountable

`getChildResources`

## Constructor Details

### SparseFixedBitSet

public SparseFixedBitSet(int length)
Create a `SparseFixedBitSet` that can contain bits between `0` included and `length` excluded.

## Method Details

### clear

public void clear()
Description copied from class: `BitSet`
Clear all the bits of the set.

Depending on the implementation, this may be significantly faster than clear(0, length).

Overrides:
  `clear` in class `BitSet`

### length

public int length()
Description copied from interface: `Bits`
Returns the number of bits in this set

### cardinality

public int cardinality()
Description copied from class: `BitSet`
Return the number of bits that are set. NOTE: this method is likely to run in linear time

Specified by:
  `cardinality` in class `BitSet`

### approximateCardinality

public int approximateCardinality()
Description copied from class: `BitSet`
Return an approximation of the cardinality of this set. Some implementations may trade accuracy for speed if they have the ability to estimate the cardinality of the set without iterating over all the data. The default implementation returns `BitSet.cardinality()`.

Specified by:
  `approximateCardinality` in class `BitSet`

### get

public boolean get(int i)
Description copied from interface: `Bits`
Returns the value of the bit with the specified `index`.

Parameters:
  `i` - index, should be non-negative and < `Bits.length()`. The result of passing negative or out of bounds values is undefined by this interface, just don't do it!
Returns:
  `true` if the bit is set, `false` otherwise.

### getAndSet

public boolean getAndSet(int i)
Description copied from class: `BitSet`
Set the bit at `i`, returning `true` if it was previously set.

Specified by:
  `getAndSet` in class `BitSet`

### set

public void set(int i)
Set the bit at index `i`.

Specified by:
  `set` in class `BitSet`

### clear

public void clear(int i)
Clear the bit at index `i`.

Specified by:
  `clear` in class `BitSet`

### clear

public void clear(int from, int to)
Description copied from class: `BitSet`
Clears a range of bits.

Specified by:
  `clear` in class `BitSet`
Parameters:
  `from` - lower index
  `to` - one-past the last bit to clear

### nextSetBit

public int nextSetBit(int i)
Description copied from class: `BitSet`
Returns the index of the first set bit starting at the index specified. `DocIdSetIterator.NO_MORE_DOCS` is returned if there are no more set bits.

Overrides:
  `nextSetBit` in class `BitSet`

### nextSetBit

public int nextSetBit(int start, int upperBound)
Description copied from class: `BitSet`
Returns the index of the first set bit from start (inclusive) until end (exclusive). `DocIdSetIterator.NO_MORE_DOCS` is returned if there are no more set bits.

Specified by:
  `nextSetBit` in class `BitSet`

### prevSetBit

public int prevSetBit(int i)
Description copied from class: `BitSet`
Returns the index of the last set bit before or on the index specified. -1 is returned if there are no more set bits.

Specified by:
  `prevSetBit` in class `BitSet`

### or

public void or(DocIdSetIterator it) throws IOException
Description copied from class: `BitSet`
Does in-place OR of the bits provided by the iterator. The state of the iterator after this operation terminates is undefined.

Overrides:
  `or` in class `BitSet`
Throws:
  `IOException`

### ramBytesUsed

public long ramBytesUsed()
Description copied from interface: `Accountable`
Return the memory usage of this object in bytes. Negative values are illegal.

### toString

public String toString()

Overrides:
  `toString` in class `Object`