Factor KeyHashCode abstraction from HashQuery

This commit is contained in:
leventov
2015-09-26 20:47:26 +03:00
parent 1b10a3e220
commit 026127cd2f
7 changed files with 71 additions and 11 deletions
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2015 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.openhft.chronicle.hash.impl.stage.entry;
import net.openhft.chronicle.algo.hashing.LongHashFunction;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
@Staged
public class InputKeyHashCode implements KeyHashCode {
@StageRef public KeySearch ks;
public long keyHash = 0;
void initKeyHash() {
keyHash = ks.inputKey.hash(LongHashFunction.city_1_1());
}
@Override
public long keyHashCode() {
return keyHash;
}
}
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2015 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.openhft.chronicle.hash.impl.stage.entry;
public interface KeyHashCode {
long keyHashCode();
}
@@ -16,7 +16,6 @@
package net.openhft.chronicle.hash.impl.stage.query;
import net.openhft.chronicle.algo.hashing.LongHashFunction;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.HashEntry;
import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
@@ -67,12 +66,6 @@ public abstract class HashQuery<K> implements HashEntry<K> {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return ks.inputKey;
}
public long hashOfKey = 0;
void initHashOfKey() {
hashOfKey = ks.inputKey.hash(LongHashFunction.city_1_1());
}
public enum EntryPresence {PRESENT, ABSENT}
@@ -17,15 +17,16 @@
package net.openhft.chronicle.hash.impl.stage.query;
import net.openhft.chronicle.hash.impl.stage.entry.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
@Staged
public abstract class QueryHashLookupSearch extends HashLookupSearch {
@StageRef HashQuery op;
@StageRef KeyHashCode h;
void initSearchKey() {
initSearchKey(hl().maskUnsetKey(hh.h().hashSplitting.segmentHash(op.hashOfKey)));
initSearchKey(hl().maskUnsetKey(hh.h().hashSplitting.segmentHash(h.keyHashCode())));
}
}
@@ -16,6 +16,7 @@
package net.openhft.chronicle.hash.impl.stage.query;
import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode;
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
@@ -23,9 +24,9 @@ import net.openhft.sg.Staged;
@Staged
public abstract class QuerySegmentStages extends SegmentStages {
@StageRef HashQuery q;
@StageRef KeyHashCode h;
void initSegmentIndex() {
segmentIndex = hh.h().hashSplitting.segmentIndex(q.hashOfKey);
segmentIndex = hh.h().hashSplitting.segmentIndex(h.keyHashCode());
}
}
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
import net.openhft.chronicle.hash.impl.stage.entry.InputKeyHashCode;
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
@@ -51,6 +52,7 @@ import net.openhft.sg.Staged;
KeyBytesInterop.class,
QuerySegmentStages.class,
KeySearch.class,
InputKeyHashCode.class,
QueryHashLookupSearch.class,
QueryHashLookupPos.class,
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
import net.openhft.chronicle.hash.impl.stage.entry.InputKeyHashCode;
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
@@ -60,6 +61,7 @@ import net.openhft.sg.Staged;
KeyBytesInterop.class,
ReplicatedQuerySegmentStages.class,
KeySearch.class,
InputKeyHashCode.class,
QueryHashLookupSearch.class,
QueryHashLookupPos.class,