forked from opensearch-project/OpenSearch
-
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.
[Refactor] Remaining HPPC to java.util collections (opensearch-projec…
…t#8730) This commit refactors the remaining usages of hppc collections to java.util collections and completely removes the obsolete hppc dependency. Signed-off-by: Nicholas Walter Knize <nknize@apache.org> Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
- Loading branch information
1 parent
3957b9b
commit 386a69a
Showing
104 changed files
with
730 additions
and
1,576 deletions.
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
libs/common/src/main/java/org/opensearch/common/util/BitMixer.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,172 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* HPPC | ||
* | ||
* Copyright (C) 2010-2022 Carrot Search s.c. | ||
* All rights reserved. | ||
* | ||
* Refer to the full license file "LICENSE.txt": | ||
* https://github.com/carrotsearch/hppc/blob/master/LICENSE.txt | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.common.util; | ||
|
||
/** | ||
* Bit mixing utilities from carrotsearch.hppc. | ||
* | ||
* Licensed under ALv2. This is pulled in directly to avoid a full hppc dependency. | ||
* | ||
* The purpose of these methods is to evenly distribute key space over int32 | ||
* range. | ||
*/ | ||
public final class BitMixer { | ||
|
||
// Don't bother mixing very small key domains much. | ||
public static int mix(byte key) { | ||
return key * PHI_C32; | ||
} | ||
|
||
public static int mix(byte key, int seed) { | ||
return (key ^ seed) * PHI_C32; | ||
} | ||
|
||
public static int mix(short key) { | ||
return mixPhi(key); | ||
} | ||
|
||
public static int mix(short key, int seed) { | ||
return mixPhi(key ^ seed); | ||
} | ||
|
||
public static int mix(char key) { | ||
return mixPhi(key); | ||
} | ||
|
||
public static int mix(char key, int seed) { | ||
return mixPhi(key ^ seed); | ||
} | ||
|
||
// Better mix for larger key domains. | ||
public static int mix(int key) { | ||
return mix32(key); | ||
} | ||
|
||
public static int mix(int key, int seed) { | ||
return mix32(key ^ seed); | ||
} | ||
|
||
public static int mix(float key) { | ||
return mix32(Float.floatToIntBits(key)); | ||
} | ||
|
||
public static int mix(float key, int seed) { | ||
return mix32(Float.floatToIntBits(key) ^ seed); | ||
} | ||
|
||
public static int mix(double key) { | ||
return (int) mix64(Double.doubleToLongBits(key)); | ||
} | ||
|
||
public static int mix(double key, int seed) { | ||
return (int) mix64(Double.doubleToLongBits(key) ^ seed); | ||
} | ||
|
||
public static int mix(long key) { | ||
return (int) mix64(key); | ||
} | ||
|
||
public static int mix(long key, int seed) { | ||
return (int) mix64(key ^ seed); | ||
} | ||
|
||
public static int mix(Object key) { | ||
return key == null ? 0 : mix32(key.hashCode()); | ||
} | ||
|
||
public static int mix(Object key, int seed) { | ||
return key == null ? 0 : mix32(key.hashCode() ^ seed); | ||
} | ||
|
||
/** | ||
* MH3's plain finalization step. | ||
*/ | ||
public static int mix32(int k) { | ||
k = (k ^ (k >>> 16)) * 0x85ebca6b; | ||
k = (k ^ (k >>> 13)) * 0xc2b2ae35; | ||
return k ^ (k >>> 16); | ||
} | ||
|
||
/** | ||
* Computes David Stafford variant 9 of 64bit mix function (MH3 finalization step, | ||
* with different shifts and constants). | ||
* | ||
* Variant 9 is picked because it contains two 32-bit shifts which could be possibly | ||
* optimized into better machine code. | ||
* | ||
* @see "http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html" | ||
*/ | ||
public static long mix64(long z) { | ||
z = (z ^ (z >>> 32)) * 0x4cd6944c5cc20b6dL; | ||
z = (z ^ (z >>> 29)) * 0xfc12c5b19d3259e9L; | ||
return z ^ (z >>> 32); | ||
} | ||
|
||
/* | ||
* Golden ratio bit mixers. | ||
*/ | ||
|
||
private static final int PHI_C32 = 0x9e3779b9; | ||
private static final long PHI_C64 = 0x9e3779b97f4a7c15L; | ||
|
||
public static int mixPhi(byte k) { | ||
final int h = k * PHI_C32; | ||
return h ^ (h >>> 16); | ||
} | ||
|
||
public static int mixPhi(char k) { | ||
final int h = k * PHI_C32; | ||
return h ^ (h >>> 16); | ||
} | ||
|
||
public static int mixPhi(short k) { | ||
final int h = k * PHI_C32; | ||
return h ^ (h >>> 16); | ||
} | ||
|
||
public static int mixPhi(int k) { | ||
final int h = k * PHI_C32; | ||
return h ^ (h >>> 16); | ||
} | ||
|
||
public static int mixPhi(float k) { | ||
final int h = Float.floatToIntBits(k) * PHI_C32; | ||
return h ^ (h >>> 16); | ||
} | ||
|
||
public static int mixPhi(double k) { | ||
final long h = Double.doubleToLongBits(k) * PHI_C64; | ||
return (int) (h ^ (h >>> 32)); | ||
} | ||
|
||
public static int mixPhi(long k) { | ||
final long h = k * PHI_C64; | ||
return (int) (h ^ (h >>> 32)); | ||
} | ||
|
||
public static int mixPhi(Object k) { | ||
final int h = (k == null ? 0 : k.hashCode() * PHI_C32); | ||
return h ^ (h >>> 16); | ||
} | ||
} |
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.