component
Class BitMemory

java.lang.Object
  extended by component.BitMemory

public class BitMemory
extends java.lang.Object

Generic implementation of a bit addressable memory.

Note: it would be a mistake (in many ways) to try to read or write fields wider than 32 bits in a single operation.

All read operations return 0 bits if a selected region is outside the BitMemory. Write operations are no-ops in those situations. (For both, this is on a bit-by-bit basis.)


Constructor Summary
BitMemory(int size)
          Construct a bit memory of size bits.
 
Method Summary
 java.lang.String dump()
          Verbose version of what an overridden toString() usually does.
 boolean equals(java.lang.Object o)
          Needed for BitMemory's to be insertable into a HashSet.
 int getSize()
          Returns the size of this BitMemory, measured in bits.
 int hashCode()
          Needed for BitMemory's to be insertable into a HashSet.
static void main(java.lang.String[] args)
          Test code/driver for this class; used for debugging BitMemory implementation only.
 int read(int start, int len)
          The memory bits at positions start,...,start+len-1 are put into the low order bits of the result.
 void write(BitMemory data, int start)
          Copy all the bits of the data BitMemory into this one, starting at offset start.
 void write(int val, int start, int len)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitMemory

public BitMemory(int size)
Construct a bit memory of size bits.

Method Detail

write

public void write(int val,
                  int start,
                  int len)

write

public void write(BitMemory data,
                  int start)
Copy all the bits of the data BitMemory into this one, starting at offset start.


read

public int read(int start,
                int len)
The memory bits at positions start,...,start+len-1 are put into the low order bits of the result. The bit at start becomes the MSB of those low-order len bits in the result.

If a bit position is out of range for this BitMemory, a 0 bit is substituted into the result.

len must be in the range 0..32 for correct operation.


getSize

public int getSize()
Returns the size of this BitMemory, measured in bits.


dump

public java.lang.String dump()
Verbose version of what an overridden toString() usually does.


hashCode

public int hashCode()
Needed for BitMemory's to be insertable into a HashSet.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Needed for BitMemory's to be insertable into a HashSet.

Overrides:
equals in class java.lang.Object

main

public static void main(java.lang.String[] args)
Test code/driver for this class; used for debugging BitMemory implementation only.