net.sourceforge.cilib.container
Class BitArray

java.lang.Object
  extended by net.sourceforge.cilib.container.BitArray
All Implemented Interfaces:
Serializable, Cloneable

public class BitArray
extends Object
implements Cloneable

This class represents an array of bit values and is efficient as the values are packed together. Ideas for this class where taken from a C++ implementation.

Author:
Gary Pampara
See Also:
Serialized Form

Constructor Summary
BitArray()
          Create a BitArray with the initial number of bits equal to 32.
BitArray(BitArray copy)
          Copy constructor.
BitArray(int numberOfBits)
          Create a BitArray with the initial number of bits specified by the parameter numberOfBits.
 
Method Summary
 void clear(int index)
          Clear the bit (make it false) located at a specific index.
 boolean get(int index)
          Return the state of the bit specified at index index.
 BitArray getClone()
          Create a cloned copy of the current object and return it.
 int length()
          This method returns the number of bits currently represented by the BitArray.
 void set(int index)
          Sets the specified bit at index index to the true / on state.
 int size()
          Returns the actual size used by the BitArray The result returned will be the size + 1.
 double valueOf(int i, int j)
          Get the value of the bits between the provided indexes, i and j.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitArray

public BitArray()
Create a BitArray with the initial number of bits equal to 32.


BitArray

public BitArray(int numberOfBits)
Create a BitArray with the initial number of bits specified by the parameter numberOfBits.

Parameters:
numberOfBits - The number of bits to set for this BitArray.

BitArray

public BitArray(BitArray copy)
Copy constructor. Create a copy of the provided instance.

Parameters:
copy - The instance to copy.
Method Detail

getClone

public BitArray getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

get

public boolean get(int index)
Return the state of the bit specified at index index.

Parameters:
index - The index of the specified bit.
Returns:
Return the bit value at index.
Throws:
IndexOutOfBoundsException - If the specified index value is invalid

set

public void set(int index)
Sets the specified bit at index index to the true / on state.

Parameters:
index - The index of the target bit
Throws:
IndexOutOfBoundsException - If the specified index value is invalid

clear

public void clear(int index)
Clear the bit (make it false) located at a specific index.

Parameters:
index - The index of the bit to be cleared.
Throws:
IndexOutOfBoundsException - If the specified index value is invalid.

size

public int size()
Returns the actual size used by the BitArray The result returned will be the size + 1.

Returns:
The size of the array (n-1) (in bytes) of the internal array

length

public int length()
This method returns the number of bits currently represented by the BitArray. This is the "length" of the BitArray

Returns:
The number of bits represented by the BitArray

valueOf

public double valueOf(int i,
                      int j)
Get the value of the bits between the provided indexes, i and j.

Parameters:
i - The start index.
j - The end index.
Returns:
The value of the bits from indexes i to j.


Copyright © 2009 CIRG. All Rights Reserved.