mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-08 19:15:14 +00:00
Standardise computation of signatures.
This commit is contained in:
parent
33d6ddc7f9
commit
8fb518e6a1
@ -22,7 +22,6 @@ import java.nio.LongBuffer;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of HashFunction that
|
* An implementation of HashFunction that
|
||||||
@ -43,6 +42,8 @@ public final class MD5Cyclic implements HashFunction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature for this hash function.
|
* The signature for this hash function.
|
||||||
|
*
|
||||||
|
* <p>TODO: Make static akin to a serialVersionUID?
|
||||||
*/
|
*/
|
||||||
private final long signature;
|
private final long signature;
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ public final class MD5Cyclic implements HashFunction {
|
|||||||
// This should not happen
|
// This should not happen
|
||||||
throw new IllegalStateException("Missing the standard MD5 message digest algorithm", e);
|
throw new IllegalStateException("Missing the standard MD5 message digest algorithm", e);
|
||||||
}
|
}
|
||||||
signature = apply(HashFunctionIdentity.prepareSignatureBuffer(this), 0);
|
signature = Signatures.getSignature(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,6 @@ package org.apache.commons.collections4.bloomfilter.hasher.function;
|
|||||||
|
|
||||||
import org.apache.commons.codec.digest.MurmurHash3;
|
import org.apache.commons.codec.digest.MurmurHash3;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of HashFunction that
|
* An implementation of HashFunction that
|
||||||
@ -32,6 +31,8 @@ public final class Murmur128x86Cyclic implements HashFunction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this hash method.
|
* The name of this hash method.
|
||||||
|
*
|
||||||
|
* <p>TODO: Should this be changed to "Murmur3_128_x64"?
|
||||||
*/
|
*/
|
||||||
public static final String NAME = "Murmur3_x64_128";
|
public static final String NAME = "Murmur3_x64_128";
|
||||||
|
|
||||||
@ -42,6 +43,8 @@ public final class Murmur128x86Cyclic implements HashFunction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature for this hash function.
|
* The signature for this hash function.
|
||||||
|
*
|
||||||
|
* <p>TODO: Make static akin to a serialVersionUID?
|
||||||
*/
|
*/
|
||||||
private final long signature;
|
private final long signature;
|
||||||
|
|
||||||
@ -49,7 +52,7 @@ public final class Murmur128x86Cyclic implements HashFunction {
|
|||||||
* Constructs a Murmur3 x64 128 hash.
|
* Constructs a Murmur3 x64 128 hash.
|
||||||
*/
|
*/
|
||||||
public Murmur128x86Cyclic() {
|
public Murmur128x86Cyclic() {
|
||||||
signature = apply(HashFunctionIdentity.prepareSignatureBuffer(this), 0);
|
signature = Signatures.getSignature(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,6 @@ package org.apache.commons.collections4.bloomfilter.hasher.function;
|
|||||||
|
|
||||||
import org.apache.commons.codec.digest.MurmurHash3;
|
import org.apache.commons.codec.digest.MurmurHash3;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of HashFunction that
|
* An implementation of HashFunction that
|
||||||
@ -32,11 +31,15 @@ public final class Murmur32x86Iterative implements HashFunction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this hash function.
|
* The name of this hash function.
|
||||||
|
*
|
||||||
|
* <p>TODO: Should this be changed to "Murmur3_32_x86"?
|
||||||
*/
|
*/
|
||||||
public static final String NAME = "Murmur3_x86_32";
|
public static final String NAME = "Murmur3_x86_32";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature for this hash function.
|
* The signature for this hash function.
|
||||||
|
*
|
||||||
|
* <p>TODO: Make static akin to a serialVersionUID?
|
||||||
*/
|
*/
|
||||||
private final long signature;
|
private final long signature;
|
||||||
|
|
||||||
@ -44,7 +47,7 @@ public final class Murmur32x86Iterative implements HashFunction {
|
|||||||
* Constructs a Murmur3 x86 32 hash
|
* Constructs a Murmur3 x86 32 hash
|
||||||
*/
|
*/
|
||||||
public Murmur32x86Iterative() {
|
public Murmur32x86Iterative() {
|
||||||
signature = apply(HashFunctionIdentity.prepareSignatureBuffer(this), 0);
|
signature = Signatures.getSignature(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,6 @@ package org.apache.commons.collections4.bloomfilter.hasher.function;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
||||||
import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of HashFunction that
|
* An implementation of HashFunction that
|
||||||
@ -39,6 +38,8 @@ public final class ObjectsHashIterative implements HashFunction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature for this hash function.
|
* The signature for this hash function.
|
||||||
|
*
|
||||||
|
* <p>TODO: Make static akin to a serialVersionUID?
|
||||||
*/
|
*/
|
||||||
private final long signature;
|
private final long signature;
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public final class ObjectsHashIterative implements HashFunction {
|
|||||||
* Constructs a hash that uses the Objects.hash method to has values.
|
* Constructs a hash that uses the Objects.hash method to has values.
|
||||||
*/
|
*/
|
||||||
public ObjectsHashIterative() {
|
public ObjectsHashIterative() {
|
||||||
signature = apply(HashFunctionIdentity.prepareSignatureBuffer(this), 0);
|
signature = Signatures.getSignature(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You 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 org.apache.commons.collections4.bloomfilter.hasher.function;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunction;
|
||||||
|
import org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow computation of HashFunction signatures.
|
||||||
|
* @since 4.5
|
||||||
|
*/
|
||||||
|
final class Signatures {
|
||||||
|
|
||||||
|
/** No instances. */
|
||||||
|
private Signatures() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the standard signature for the hash function. The signature is prepared as:
|
||||||
|
* <pre><code>
|
||||||
|
* int seed = 0;
|
||||||
|
* return hashFunction.apply(HashFunctionIdentity.prepareSignatureBuffer(hashFunction), seed);
|
||||||
|
* </code></pre>
|
||||||
|
*
|
||||||
|
* @param hashFunction the hash function
|
||||||
|
* @return the signature
|
||||||
|
* @see HashFunctionIdentity#prepareSignatureBuffer(HashFunctionIdentity)
|
||||||
|
* @see HashFunction#apply(byte[], int)
|
||||||
|
*/
|
||||||
|
static long getSignature(HashFunction hashFunction) {
|
||||||
|
return hashFunction.apply(HashFunctionIdentity.prepareSignatureBuffer(hashFunction), 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user