mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-352 Changed garbage-free Chronicle-Map iterations API from old to new Contexts; Add SegmentContexts API
This commit is contained in:
@@ -22,7 +22,7 @@ import net.openhft.chronicle.hash.ChronicleHashBuilder;
|
||||
import net.openhft.chronicle.hash.serialization.internal.SerializationBuilder;
|
||||
|
||||
//TODO remove this temporary interface
|
||||
public interface ChronicleHashBuilderImpl<K, H extends ChronicleHash<K, ?, ?>,
|
||||
public interface ChronicleHashBuilderImpl<K, H extends ChronicleHash<K, ?, ?, ?>,
|
||||
B extends ChronicleHashBuilder<K, H, B>> extends ChronicleHashBuilder<K, H, B> {
|
||||
|
||||
SerializationBuilder<K> keyBuilder();
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.hash.ChronicleHash;
|
||||
import net.openhft.chronicle.hash.ExternalHashQueryContext;
|
||||
import net.openhft.chronicle.hash.KeyContext;
|
||||
import net.openhft.chronicle.hash.*;
|
||||
import net.openhft.chronicle.hash.impl.hashlookup.HashLookup;
|
||||
import net.openhft.chronicle.hash.impl.util.BuildVersion;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
@@ -44,8 +42,9 @@ import static java.lang.Math.max;
|
||||
import static net.openhft.lang.MemoryUnit.*;
|
||||
|
||||
public abstract class VanillaChronicleHash<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
C extends KeyContext<K>, ECQ extends ExternalHashQueryContext<K>>
|
||||
implements ChronicleHash<K, C, ECQ>, Serializable {
|
||||
C extends HashEntry<K>, SC extends HashSegmentContext<K, ?>,
|
||||
ECQ extends ExternalHashQueryContext<K>>
|
||||
implements ChronicleHash<K, C, SC, ECQ>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
|
||||
@@ -21,5 +21,5 @@ package net.openhft.chronicle.hash.impl;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
|
||||
public interface VanillaChronicleHashHolder<K, KI, MKI extends MetaBytesInterop<K, ? super KI>> {
|
||||
VanillaChronicleHash<K, KI, MKI, ?, ?> h();
|
||||
VanillaChronicleHash<K, KI, MKI, ?, ?, ?> h();
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ public abstract class SegmentStages implements SegmentLock {
|
||||
}
|
||||
|
||||
void initSegment() {
|
||||
VanillaChronicleHash<?, ?, ?, ?, ?> h = hh.h();
|
||||
VanillaChronicleHash<?, ?, ?, ?, ?, ?> h = hh.h();
|
||||
long hashLookupOffset = h.segmentOffset(segmentIndex);
|
||||
long freeListOffset = hashLookupOffset + h.segmentHashLookupOuterSize;
|
||||
freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize);
|
||||
@@ -375,7 +375,7 @@ public abstract class SegmentStages implements SegmentLock {
|
||||
|
||||
//TODO refactor/optimize
|
||||
public long alloc(int chunks) {
|
||||
VanillaChronicleHash<?, ?, ?, ?, ?> h = hh.h();
|
||||
VanillaChronicleHash<?, ?, ?, ?, ?, ?> h = hh.h();
|
||||
if (chunks > h.maxChunksPerEntry)
|
||||
throw new IllegalArgumentException("Entry is too large: requires " + chunks +
|
||||
" entry size chucks, " + h.maxChunksPerEntry + " is maximum.");
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Staged
|
||||
@@ -50,7 +51,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>> implements
|
||||
this.entryRemovedOnThisIteration = entryRemovedOnThisIteration;
|
||||
}
|
||||
|
||||
public boolean forEachRemoving(Predicate<? super E> action) {
|
||||
public boolean forEachSegmentEntryWhile(Predicate<? super E> action) {
|
||||
s.innerUpdateLock.lock();
|
||||
try {
|
||||
long size = s.size();
|
||||
@@ -86,6 +87,13 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>> implements
|
||||
initEntryRemovedOnThisIteration(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachSegmentEntry(Consumer<? super E> action) {
|
||||
forEachSegmentEntryWhile(e -> {
|
||||
action.accept(e);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void checkEntryNotRemovedOnThisIteration() {
|
||||
if (entryRemovedOnThisIterationInit())
|
||||
|
||||
Reference in New Issue
Block a user