mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
allow Byteable instances that have maxSize() determined at runtime
This commit is contained in:
@@ -19,29 +19,28 @@ package net.openhft.lang.values;
|
||||
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.bytes.DynamicallySized;
|
||||
import net.openhft.chronicle.bytes.NativeBytesStore;
|
||||
import net.openhft.chronicle.values.Copyable;
|
||||
|
||||
/**
|
||||
* Created by peter.lawrey on 23/04/2015.
|
||||
*/
|
||||
public class DoubleArray implements Byteable, Copyable<DoubleArray> {
|
||||
public class DoubleArray implements Byteable, Copyable<DoubleArray>, DynamicallySized {
|
||||
static boolean HACK = true;
|
||||
private static int CAPACITY = 0; // assume a 32-bit size.
|
||||
private static int LENGTH = CAPACITY + 4; // assume a 32-bit size.
|
||||
private static int BASE = LENGTH + 4;
|
||||
|
||||
private final int capacity;
|
||||
private BytesStore bs;
|
||||
private long offset;
|
||||
|
||||
// creates an empty DoubleArray
|
||||
public DoubleArray() {
|
||||
}
|
||||
|
||||
public DoubleArray(int capacity) {
|
||||
bs = NativeBytesStore.nativeStoreWithFixedCapacity(BASE + capacity * 8L);
|
||||
bs.writeInt(CAPACITY, capacity);
|
||||
offset = 0;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +61,7 @@ public class DoubleArray implements Byteable, Copyable<DoubleArray> {
|
||||
|
||||
@Override
|
||||
public long maxSize() {
|
||||
return BASE + length() * 8;
|
||||
return BASE + capacity * 8;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
|
||||
@@ -67,7 +67,6 @@ public class DoubleArrayTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("TODO What is HACK???")
|
||||
public void addToAMap() {
|
||||
DoubleArray a = new DoubleArray(10);
|
||||
a.setData(new double[]{1, 2, 3, 4, 5});
|
||||
@@ -77,6 +76,7 @@ public class DoubleArrayTest {
|
||||
|
||||
ChronicleMap<Integer, DoubleArray> proxyMap = ChronicleMap
|
||||
.of(Integer.class, DoubleArray.class)
|
||||
.constantValueSizeBySample(a)
|
||||
.entries(2)
|
||||
.create();
|
||||
proxyMap.put(1, a);
|
||||
|
||||
Reference in New Issue
Block a user