coins.alias.util
Class BitVectorIterator

java.lang.Object
  extended bycoins.alias.util.BitVectorIterator

public class BitVectorIterator
extends java.lang.Object

BitVectorIteratorImpl class: (##6)

This class offers methods for iterating over a BitVector instance. As BitVectors in general cannot be efficiently scanned, this class is just a compromise for when there is really a need to scan over a BitVector. If iteration performance is important, other data structures than a BitVector should be considered.

The iteration is implemented by maintaining and advancing the cursor position, which is the bit position of the underlying BitVector this BitVectorIterator currently has hold on.

The methods in this class do not necessarily throw appropriate exceptions; an instance of this class may silently enter an invalid state, so care should be taken.

Some of the methods' names (hasNext and next) are carried over from java.util.Iterator interface, but their behaviors may be different from what may be expected from their names.


Constructor Summary
BitVectorIterator(BitVector pBitVector)
          Creates a BitVectorIterator instance that scans the given argument.
 
Method Summary
 int currentIndex()
          Returns the current cursor position.
 boolean hasNext()
          Returns true if the cursor is not at or beyond the end of the underlying BitVector.
 int next()
          Returns the next bit position and advances the cursor by one.
 int nextIndex()
          Returns the next bit position that is set and advances the cursor up to the returned position.
 void resetBit()
          Resets the bit at the current cursor position.
 void setBit()
          Sets the bit at the current cursor position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitVectorIterator

public BitVectorIterator(BitVector pBitVector)
Creates a BitVectorIterator instance that scans the given argument. The cursor position (returned by currentIndex) is set to -1.

Parameters:
pBitVector - the BitVector this BitVectorIterator scans.
Method Detail

hasNext

public boolean hasNext()
Returns true if the cursor is not at or beyond the end of the underlying BitVector. (In other words, returns true if next would return a number less than the length of the underlying BitVector.)

Returns:
true if iteration has more elements.

next

public int next()
Returns the next bit position and advances the cursor by one. The value returned by this method may not be within the length of the underlying BitVector.

Returns:
the next bit position.

nextIndex

public int nextIndex()
Returns the next bit position that is set and advances the cursor up to the returned position. If there is no remaining bit that is set, returns -1, and the cursor will be at the end of the underlying BitVector.

Returns:
the next bit position that is set, or -1 if there is no such bit.

currentIndex

public int currentIndex()
Returns the current cursor position.

Returns:
the current cursor position.

resetBit

public void resetBit()
Resets the bit at the current cursor position.


setBit

public void setBit()
Sets the bit at the current cursor position.