forked from leventov/Koloboke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mixing for hashes with primitive keys
- Loading branch information
Showing
6 changed files
with
167 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
lib/impl/src/main/javaTemplates/net/openhft/collect/impl/hash/LHash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* with LHash hash */ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* 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.collect.impl.hash; | ||
|
||
public interface LHash extends Hash { | ||
|
||
/** = round(2 ^ 32 * (sqrt(5) - 1)), Java form of unsigned 2654435769 */ | ||
static final int INT_PHI_MAGIC = -1640531527; | ||
/** ~= round(2 ^ 64 * (sqrt(5) - 1)), Java form of 11400714819323198485 */ | ||
static final long LONG_PHI_MAGIC = -7046029254386353131L; | ||
|
||
static final int BYTE_MIX_SHIFT = 6; | ||
static final int CHAR_MIX_SHIFT = 10, SHORT_MIX_SHIFT = CHAR_MIX_SHIFT; | ||
static final int INT_MIX_SHIFT = 16, FLOAT_MIX_SHIFT = INT_MIX_SHIFT; | ||
|
||
/* with Separate|Parallel kv */ | ||
|
||
/* with byte|char|short|int|float key */ | ||
static class SeparateKVByteKeyMixing { | ||
static int mix(/* bits */byte key) { | ||
int h = key * INT_PHI_MAGIC; | ||
return h ^ (h >> BYTE_MIX_SHIFT); | ||
} | ||
} | ||
/* endwith */ | ||
|
||
/* with double|long key */ | ||
static class SeparateKVDoubleKeyMixing { | ||
static int mix(long key) { | ||
long h = key * LONG_PHI_MAGIC; | ||
h ^= h >> 32; | ||
return (int) (h ^ (h >> INT_MIX_SHIFT)); | ||
} | ||
} | ||
/* endwith */ | ||
|
||
static class SeparateKVObjKeyMixing { | ||
static int mix(int hash) { | ||
return hash ^ (hash >> INT_MIX_SHIFT); | ||
} | ||
} | ||
|
||
/* endwith */ | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
lib/impl/src/main/javaTemplates/net/openhft/collect/impl/hash/QHash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* with QHash hash */ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* 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.collect.impl.hash; | ||
|
||
import static net.openhft.collect.impl.hash.LHash.*; | ||
|
||
|
||
public interface QHash extends Hash { | ||
/* with Separate|Parallel kv */ | ||
|
||
/* with byte|char|short|int|float key */ | ||
static class SeparateKVByteKeyMixing { | ||
static int mix(/* bits */byte key) { | ||
return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE; | ||
} | ||
} | ||
/* endwith */ | ||
|
||
/* with double|long key */ | ||
static class SeparateKVDoubleKeyMixing { | ||
static int mix(long key) { | ||
long h = key * LONG_PHI_MAGIC; | ||
/* if Separate kv */ | ||
h ^= h >> 32; | ||
return ((int) h) & Integer.MAX_VALUE; | ||
/* elif Parallel kv */ | ||
// not to loose information about 63-64-th bits | ||
h ^= (h >> 40) ^ (h >> 24); | ||
return ((((int) h) << 2) >>> 1); | ||
/* endif */ | ||
} | ||
} | ||
/* endwith */ | ||
|
||
static class SeparateKVObjKeyMixing { | ||
static int mix(int hash) { | ||
/* if Separate kv */ | ||
return hash & Integer.MAX_VALUE; | ||
/* elif Parallel kv */ | ||
return (hash << 2) >>> 1; | ||
/* endif */ | ||
} | ||
} | ||
|
||
/* endwith */ | ||
} |