- private BitVector[] memory;
-
- public Page()
- {
- memory = new BitVector[pageSize];
- }
-
- public BitVector getCell(int index)
- {
- BitVector b = memory[index];
- if (b == null)
- return BitVector.of(Bit.ZERO, cellWidth);
- return memory[index];
- }
-
- public void setCell(int index, BitVector bits)
- {
- if (bits.width() != cellWidth)
- throw new IllegalArgumentException(String.format(
- "BitVector to be saved in memory cell has unexpected width. Expected: %d Actual: %d", cellWidth, bits.width()));
- memory[index] = bits;
- }
-
- public void setCellAsBigInteger(int index, BigInteger bits)
- {
- setCell(index, BitVector.from(bits, cellWidth));
- }
-
- public BigInteger getCellAsBigInteger(int index)
- {
- try {
- return getCell(index).getUnsignedValue();
- }
- catch(NumberFormatException e)
- {
- throw new MemoryException(e);
- }
- }
-
- @Override
- public String toString()
- {
- return Arrays.deepToString(memory);
- }