org.apache.lucene.util

## Class BitVector

- java.lang.Object
- - org.apache.lucene.util.BitVector

- All Implemented Interfaces:
    java.lang.Cloneable

      public final class BitVector
      extends java.lang.Object
      implements java.lang.Cloneable

  Optimized implementation of a vector of bits. This is more-or-less like java.util.BitSet, but also includes the following:
  - a count() method, which efficiently computes the number of one bits;
  - optimized read from and write to disk;
  - inlinable get() method;
  - store and load, as bit set or d-gaps, depending on sparseness;
  Version:
    $Id: BitVector.java 950306 2010-06-01 23:33:34Z mikemccand $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitVector(Directory d, java.lang.String name)` Constructs a bit vector from the file `name` in Directory `d`, as written by the `write(org.apache.lucene.store.Directory, java.lang.String)` method.
    `BitVector(int n)` Constructs a vector capable of holding `n` bits.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear(int bit)` Sets the value of `bit` to zero.
    `java.lang.Object` | `clone()`
    `int` | `count()` Returns the total number of one bits in this vector.
    `boolean` | `get(int bit)` Returns `true` if `bit` is one and `false` if it is zero.
    `boolean` | `getAndSet(int bit)` Sets the value of `bit` to true, and returns true if bit was already set
    `int` | `getRecomputedCount()` For testing
    `void` | `set(int bit)` Sets the value of `bit` to one.
    `int` | `size()` Returns the number of bits in this vector.
    `BitVector` | `subset(int start, int end)` Retrieve a subset of this BitVector.
    `void` | `write(Directory d, java.lang.String name)` Writes this vector to the file `name` in Directory `d`, in a format that can be read by the constructor `BitVector(Directory, String)`.

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

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

- - ### Constructor Detail

    - #### BitVector

          public BitVector(int n)

      Constructs a vector capable of holding `n` bits.

    - #### BitVector

          public BitVector(Directory d,
                           java.lang.String name)
                    throws java.io.IOException

      Constructs a bit vector from the file `name` in Directory `d`, as written by the `write(org.apache.lucene.store.Directory, java.lang.String)` method.
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `java.lang.Object`

    - #### set

          public final void set(int bit)

      Sets the value of `bit` to one.

    - #### getAndSet

          public final boolean getAndSet(int bit)

      Sets the value of `bit` to true, and returns true if bit was already set

    - #### clear

          public final void clear(int bit)

      Sets the value of `bit` to zero.

    - #### get

          public final boolean get(int bit)

      Returns `true` if `bit` is one and `false` if it is zero.

    - #### size

          public final int size()

      Returns the number of bits in this vector. This is also one greater than the number of the largest valid bit number.

    - #### count

          public final int count()

      Returns the total number of one bits in this vector. This is efficiently computed and cached, so that, if the vector is not changed, no recomputation is done for repeated calls.

    - #### getRecomputedCount

          public final int getRecomputedCount()

      For testing

    - #### write

          public final void write(Directory d,
                                  java.lang.String name)
                           throws java.io.IOException

      Writes this vector to the file `name` in Directory `d`, in a format that can be read by the constructor `BitVector(Directory, String)`.
      Throws:
        `java.io.IOException`

    - #### subset

          public BitVector subset(int start,
                                  int end)

      Retrieve a subset of this BitVector.
      Parameters:
        `start` - starting index, inclusive
        `end` - ending index, exclusive
      Returns:
        subset

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.