aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/btree/HeapPage.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/trygvis/btree/HeapPage.java')
-rw-r--r--src/main/java/io/trygvis/btree/HeapPage.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/io/trygvis/btree/HeapPage.java b/src/main/java/io/trygvis/btree/HeapPage.java
index a931260..32ba0ef 100644
--- a/src/main/java/io/trygvis/btree/HeapPage.java
+++ b/src/main/java/io/trygvis/btree/HeapPage.java
@@ -53,11 +53,27 @@ public class HeapPage {
bytes.putInt(FREE_POSITION_INDEX, freePosition);
}
+ public void prepend(byte[] item) {
+ int bytesFree = bytesFree();
+ int bytesRequested = item.length;
+
+ if (bytesRequested > bytesFree) {
+ throw new PageOverflowException(bytesFree, bytesRequested);
+ }
+
+ byte[] array = bytes.array();
+ int offset = bytes.arrayOffset();
+
+ System.arraycopy(array, offset, array, offset + bytesRequested, bytesRequested);
+
+ freePosition -= itemSize;
+ }
+
public int bytesFree() {
return freePosition - headerSize;
}
- public Iterable<ByteBuffer> bufferIterator() {
+ public Iterable<ByteBuffer> items() {
return new Iterable<ByteBuffer>() {
@Override
public Iterator<ByteBuffer> iterator() {