mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-198 Add a long -> long test.
This commit is contained in:
@@ -43,6 +43,8 @@ public enum Hasher {
|
||||
}
|
||||
|
||||
public static long hash(Bytes bytes, long offset, long limit) {
|
||||
if (limit - offset == 8)
|
||||
return Maths.hash(bytes.readLong(offset));
|
||||
long h = 0;
|
||||
long i = offset;
|
||||
for (; i < limit - 7; i += 8)
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2014 Higher Frequency Trading
|
||||
*
|
||||
* http://www.higherfrequencytrading.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash.serialization.internal;
|
||||
|
||||
import net.openhft.chronicle.hash.serialization.BytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.Hasher;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
|
||||
public enum LongValueMarshaller
|
||||
implements BytesInterop<LongValue>, BytesReader<LongValue>, SizeMarshaller {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public long size(LongValue e) {
|
||||
return 8L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sizeEncodingSize(long size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSize(Bytes bytes, long size) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startsWith(Bytes bytes, LongValue e) {
|
||||
return e.getValue() == bytes.readLong(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long hash(LongValue e) {
|
||||
return Hasher.hash(e.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Bytes bytes, LongValue e) {
|
||||
bytes.writeLong(e.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readSize(Bytes bytes) {
|
||||
return 8L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongValue read(Bytes bytes, long size) {
|
||||
return read(bytes, size, DataValueClasses.newInstance(LongValue.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongValue read(Bytes bytes, long size, LongValue toReuse) {
|
||||
toReuse.setValue(bytes.readLong());
|
||||
return toReuse;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaProvider;
|
||||
import net.openhft.chronicle.map.MultiMapFactory;
|
||||
import net.openhft.chronicle.set.ChronicleSetBuilder;
|
||||
import net.openhft.lang.Maths;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
@@ -400,10 +399,12 @@ public abstract class AbstractChronicleMapBuilder<K, V,
|
||||
if (size < 100 * 1000)
|
||||
return 1024;
|
||||
if (size < 1000 * 1000)
|
||||
return 2048;
|
||||
return 2 * 1024;
|
||||
if (size < 10 * 1000 * 1000)
|
||||
return 4096;
|
||||
return 8192;
|
||||
return 4 * 1024;
|
||||
if (size < 100 * 1000 * 1000)
|
||||
return 8 * 1024;
|
||||
return 16 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -439,7 +440,7 @@ public abstract class AbstractChronicleMapBuilder<K, V,
|
||||
int segmentHeaderSize() {
|
||||
int segments = actualSegments();
|
||||
// reduce false sharing unless we have a lot of segments.
|
||||
return segments <= 8192 ? 128 : 64;
|
||||
return segments <= 16 * 1024 ? 64 : 32;
|
||||
}
|
||||
|
||||
MultiMapFactory multiMapFactory() {
|
||||
|
||||
Reference in New Issue
Block a user