From 026127cd2f02e033294b451ddaf8b3ab4119f80e Mon Sep 17 00:00:00 2001 From: leventov Date: Sat, 26 Sep 2015 20:47:26 +0300 Subject: [PATCH] Factor KeyHashCode abstraction from HashQuery --- .../impl/stage/entry/InputKeyHashCode.java | 39 +++++++++++++++++++ .../hash/impl/stage/entry/KeyHashCode.java | 22 +++++++++++ .../hash/impl/stage/query/HashQuery.java | 7 ---- .../stage/query/QueryHashLookupSearch.java | 5 ++- .../impl/stage/query/QuerySegmentStages.java | 5 ++- .../chronicle/map/impl/MapQueryContext.java | 2 + .../map/impl/ReplicatedMapQueryContext.java | 2 + 7 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 src/main/java/net/openhft/chronicle/hash/impl/stage/entry/InputKeyHashCode.java create mode 100644 src/main/java/net/openhft/chronicle/hash/impl/stage/entry/KeyHashCode.java diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/InputKeyHashCode.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/InputKeyHashCode.java new file mode 100644 index 000000000..3eff5343f --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/InputKeyHashCode.java @@ -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 . + */ + +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; + } +} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/KeyHashCode.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/KeyHashCode.java new file mode 100644 index 000000000..574cb2a5a --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/KeyHashCode.java @@ -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 . + */ + +package net.openhft.chronicle.hash.impl.stage.entry; + +public interface KeyHashCode { + + long keyHashCode(); +} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java index be9333dd8..ecd679073 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java @@ -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 implements HashEntry { checkOnEachPublicOperation.checkOnEachPublicOperation(); return ks.inputKey; } - - public long hashOfKey = 0; - - void initHashOfKey() { - hashOfKey = ks.inputKey.hash(LongHashFunction.city_1_1()); - } public enum EntryPresence {PRESENT, ABSENT} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryHashLookupSearch.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryHashLookupSearch.java index 907698567..6ed03ed27 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryHashLookupSearch.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QueryHashLookupSearch.java @@ -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()))); } } diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QuerySegmentStages.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QuerySegmentStages.java index befe27c5a..53d9b9dfe 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QuerySegmentStages.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/QuerySegmentStages.java @@ -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()); } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/MapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/MapQueryContext.java index 9afefde58..972738da1 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/MapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/MapQueryContext.java @@ -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, diff --git a/src/main/java/net/openhft/chronicle/map/impl/ReplicatedMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/ReplicatedMapQueryContext.java index 85e080f3c..f258028f1 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/ReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/ReplicatedMapQueryContext.java @@ -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,