mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Cleaned up MultiMaps
This commit is contained in:
@@ -18,8 +18,16 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.lang.Maths;
|
||||
import net.openhft.lang.collection.ATSDirectBitSet;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
|
||||
import static net.openhft.lang.Maths.isPowerOf2;
|
||||
import static net.openhft.lang.MemoryUnit.BITS;
|
||||
import static net.openhft.lang.MemoryUnit.BYTES;
|
||||
import static net.openhft.lang.MemoryUnit.LONGS;
|
||||
|
||||
/**
|
||||
* Created by peter on 09/11/14.
|
||||
*
|
||||
@@ -32,11 +40,6 @@ enum MultiMapFactory {
|
||||
return ShortShortMultiMap.sizeInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sizeOfBitSetInBytes(long minCapacity) {
|
||||
return ShortShortMultiMap.sizeOfBitSetInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
return new ShortShortMultiMap(bytes, bitSetBytes);
|
||||
@@ -48,11 +51,6 @@ enum MultiMapFactory {
|
||||
return Int24Int24MultiMap.sizeInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sizeOfBitSetInBytes(long minCapacity) {
|
||||
return Int24Int24MultiMap.sizeOfBitSetInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
return new Int24Int24MultiMap(bytes, bitSetBytes);
|
||||
@@ -64,11 +62,6 @@ enum MultiMapFactory {
|
||||
return IntIntMultiMap.sizeInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sizeOfBitSetInBytes(long minCapacity) {
|
||||
return IntIntMultiMap.sizeOfBitSetInBytes(minCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
return new IntIntMultiMap(bytes, bitSetBytes);
|
||||
@@ -88,9 +81,29 @@ enum MultiMapFactory {
|
||||
throw new IllegalArgumentException("Capacity " + capacity + " not supported");
|
||||
}
|
||||
|
||||
public abstract long sizeInBytes(long minCapacity);
|
||||
public static long sizeOfBitSetInBytes(long minCapacity) {
|
||||
return BYTES.convert(LONGS.align(multiMapCapacity(minCapacity), BITS), BITS);
|
||||
}
|
||||
|
||||
public abstract long sizeOfBitSetInBytes(long minCapacity);
|
||||
public static ATSDirectBitSet newPositions(long capacity) {
|
||||
if (!isPowerOf2(capacity))
|
||||
throw new AssertionError("capacity should be a power of 2");
|
||||
capacity = LONGS.align(capacity, BITS);
|
||||
return new ATSDirectBitSet(DirectStore.allocateLazy(BYTES.convert(capacity, BITS)).bytes());
|
||||
}
|
||||
|
||||
static long multiMapCapacity(long minCapacity) {
|
||||
if (minCapacity < 0L)
|
||||
throw new IllegalArgumentException("minCapacity should be positive");
|
||||
long capacity = Maths.nextPower2(minCapacity, 16L);
|
||||
if (((double) minCapacity) / capacity > 2./3.) {
|
||||
// multi map shouldn't be too dense
|
||||
capacity <<= 1L;
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public abstract long sizeInBytes(long minCapacity);
|
||||
|
||||
public abstract MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user