Implemented forEachEntry() and forEachEntryWhile()

This commit is contained in:
leventov
2015-01-20 01:00:38 +07:00
parent f53a93275c
commit 06b326ab05
34 changed files with 575 additions and 239 deletions
@@ -44,7 +44,7 @@ import static net.openhft.lang.io.NativeBytes.UNSAFE;
class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
V, VI, MVI extends MetaBytesInterop<V, ? super VI>>
implements MapKeyContext<V> {
implements MapKeyContext<K, V> {
static interface ContextFactory<T extends VanillaContext> {
T createContext(VanillaContext root, int indexInContextCache);
@@ -433,6 +433,18 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
return keySize;
}
@NotNull
@Override
public K key() {
if (key != null)
return key;
initKeySearch();
initMapAndContextLocals();
mapAndContextLocalsReference.mapAndContextLocals.reusableKey =
key0(mapAndContextLocalsReference.mapAndContextLocals.reusableKey);
assert key != null;
return key;
}
/////////////////////////////////////////////////
// Key hash
@@ -1654,7 +1666,7 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
if (containsKey()) {
initEntrySizeInChunks();
upgradeToWriteLock();
hashLookup.remove();
hashLookupRemove();
free(pos, entrySizeInChunks);
size(size() - 1L);
state = DELETED;
@@ -1664,6 +1676,13 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
}
boolean forEachEntry;
void hashLookupRemove() {
if (!forEachEntry)
hashLookup.remove();
}
void initRemoveDependencies() {
initSegment();
initLocks();
@@ -1901,9 +1920,13 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
K immutableKey() {
return key0(null);
}
K key0(K usingKey) {
initKeyReader();
entry.position(keyOffset);
key = keyReader.read(entry, keySize, null);
key = keyReader.read(entry, keySize, usingKey);
return key;
}