forked from apache/pulsar
-
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.
Add circe source code to checksum library (apache#44)
- Loading branch information
Showing
60 changed files
with
4,713 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
This license applies to all parts of Protocol Buffers except the following: | ||
|
||
- Atomicops support for generic gcc, located in | ||
src/google/protobuf/stubs/atomicops_internals_generic_gcc.h. | ||
This file is copyrighted by Red Hat Inc. | ||
|
||
- Atomicops support for AIX/POWER, located in | ||
src/google/protobuf/stubs/atomicops_internals_power.h. | ||
This file is copyrighted by Bloomberg Finance LP. | ||
|
||
Copyright 2014, Google Inc. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
Code generated by the Protocol Buffer compiler is owned by the owner | ||
of the input file used when generating it. This code is not | ||
standalone and requires a support library to be linked with it. This | ||
support library is itself covered by the above license. |
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
188 changes: 188 additions & 0 deletions
188
pulsar-checksum/src/main/java/com/scurrilous/circe/CommonHashes.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,188 @@ | ||
/******************************************************************************* | ||
* Copyright 2014 Trevor Robinson | ||
* | ||
* 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 com.scurrilous.circe; | ||
|
||
import com.scurrilous.circe.params.CrcParameters; | ||
import com.scurrilous.circe.params.MurmurHash3Parameters; | ||
import com.scurrilous.circe.params.MurmurHash3Variant; | ||
import com.scurrilous.circe.params.SimpleHashParameters; | ||
import com.scurrilous.circe.params.SipHash24Parameters; | ||
|
||
/** | ||
* Static methods to obtain commonly-used hash functions. Note that a suitable | ||
* provider JAR must be made available on the class path. This class does not | ||
* have direct access to specific implementations; it simply constructs the hash | ||
* parameters and uses the {@link Hashes} class to search for a provider. | ||
*/ | ||
public final class CommonHashes { | ||
|
||
private CommonHashes() { | ||
} | ||
|
||
/** | ||
* Returns an incremental stateless hash function implementing the | ||
* {@linkplain CrcParameters#CRC32 CRC-32} checksum algorithm. | ||
* | ||
* @return a CRC-32 stateless incremental integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static IncrementalIntHash crc32() { | ||
return Hashes.getIncrementalInt(CrcParameters.CRC32); | ||
} | ||
|
||
/** | ||
* Returns an incremental stateless hash function implementing the | ||
* {@linkplain CrcParameters#CRC32C CRC-32C} checksum algorithm. | ||
* | ||
* @return a CRC-32C stateless incremental integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static IncrementalIntHash crc32c() { | ||
return Hashes.getIncrementalInt(CrcParameters.CRC32C); | ||
} | ||
|
||
/** | ||
* Returns an incremental stateless hash function implementing the | ||
* {@linkplain CrcParameters#CRC64 CRC-64} checksum algorithm. | ||
* | ||
* @return a CRC-64 stateless incremental long integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static IncrementalLongHash crc64() { | ||
return Hashes.getIncrementalLong(CrcParameters.CRC64); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the MurmurHash3 algorithm, 32-bit | ||
* x86 variant, with a seed of 0. | ||
* | ||
* @return a MurmurHash3 32-bit/x86 stateless integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatelessIntHash murmur3_32() { | ||
return Hashes.getStatelessInt(new MurmurHash3Parameters(MurmurHash3Variant.X86_32)); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the MurmurHash3 algorithm, 32-bit | ||
* x86 variant, with the given seed value | ||
* | ||
* @param seed the 32-bit seed value | ||
* @return a MurmurHash3 32-bit/x86 stateless integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatelessIntHash murmur3_32(int seed) { | ||
return Hashes.getStatelessInt(new MurmurHash3Parameters(MurmurHash3Variant.X86_32, seed)); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the MurmurHash3 algorithm, 128-bit | ||
* x64 variant, with a seed of 0. | ||
* | ||
* @return a MurmurHash3 128-bit/x64 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash murmur3_128() { | ||
return Hashes.createStateful(new MurmurHash3Parameters(MurmurHash3Variant.X64_128)); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the MurmurHash3 algorithm, 128-bit | ||
* x64 variant, with the given seed value. | ||
* | ||
* @param seed the 32-bit seed value | ||
* @return a MurmurHash3 128-bit/x64 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash murmur3_128(int seed) { | ||
return Hashes.createStateful(new MurmurHash3Parameters(MurmurHash3Variant.X64_128, seed)); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) | ||
* with the default seed, | ||
* {@code 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F}. | ||
* | ||
* @return a SipHash-2-4 stateless long integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatelessLongHash sipHash24() { | ||
return Hashes.getStatelessLong(new SipHash24Parameters()); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) | ||
* with the given seed value. | ||
* | ||
* @param seedLow the low-order 64 bits of the seed | ||
* @param seedHigh the high-order 64 bits of the seed | ||
* @return a SipHash-2-4 stateless long integer hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatelessLongHash sipHash24(long seedLow, long seedHigh) { | ||
return Hashes.getStatelessLong(new SipHash24Parameters(seedLow, seedHigh)); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the MD5 algorithm (128 bits). | ||
* | ||
* @return an MD5 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash md5() { | ||
return Hashes.createStateful(SimpleHashParameters.MD5); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SHA-1 algorithm (160 bits). | ||
* | ||
* @return a SHA-1 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash sha1() { | ||
return Hashes.createStateful(SimpleHashParameters.SHA1); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SHA-256 algorithm (256 bits). | ||
* | ||
* @return a SHA-256 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash sha256() { | ||
return Hashes.createStateful(SimpleHashParameters.SHA256); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SHA-384 algorithm (384 bits). | ||
* | ||
* @return a SHA-384 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash sha384() { | ||
return Hashes.createStateful(SimpleHashParameters.SHA384); | ||
} | ||
|
||
/** | ||
* Returns a hash function implementing the SHA-512 algorithm (512 bits). | ||
* | ||
* @return a SHA-512 stateful hash | ||
* @throws UnsupportedOperationException if no provider is available | ||
*/ | ||
public static StatefulHash sha512() { | ||
return Hashes.createStateful(SimpleHashParameters.SHA512); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
pulsar-checksum/src/main/java/com/scurrilous/circe/Hash.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,53 @@ | ||
/******************************************************************************* | ||
* Copyright 2014 Trevor Robinson | ||
* | ||
* 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 com.scurrilous.circe; | ||
|
||
/** | ||
* Abstract hash function. Each actual hash function is provided using a | ||
* {@linkplain StatefulHash stateful} derived interface. Hash functions with an | ||
* output length that fits within an {@code int} or a {@code long} are also | ||
* generally provided using a {@linkplain StatelessHash stateless} derived | ||
* interface. Given a stateless hash object, a method is provided for obtaining | ||
* a new corresponding stateful object. | ||
*/ | ||
public interface Hash { | ||
|
||
/** | ||
* Returns the canonical name of this hash algorithm. | ||
* | ||
* @return the name of this hash algorithm | ||
*/ | ||
String algorithm(); | ||
|
||
/** | ||
* Returns the length in bytes of the output of this hash function. | ||
* | ||
* @return the hash length in bytes | ||
*/ | ||
int length(); | ||
|
||
/** | ||
* Returns whether this hash function supports unsafe access to arbitrary | ||
* memory addresses using methods such as | ||
* {@link StatefulHash#update(long, long)}, | ||
* {@link StatelessIntHash#calculate(long, long)}, or | ||
* {@link IncrementalIntHash#resume(int, long, long)}. Such functions are | ||
* generally implemented in native code. | ||
* | ||
* @return true if unsafe access is supported, false if not | ||
*/ | ||
boolean supportsUnsafe(); | ||
} |
30 changes: 30 additions & 0 deletions
30
pulsar-checksum/src/main/java/com/scurrilous/circe/HashParameters.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,30 @@ | ||
/******************************************************************************* | ||
* Copyright 2014 Trevor Robinson | ||
* | ||
* 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 com.scurrilous.circe; | ||
|
||
/** | ||
* Base interface implemented by classes describing parameters for a particular | ||
* family of hash algorithms. | ||
*/ | ||
public interface HashParameters { | ||
|
||
/** | ||
* Returns the canonical name of the hash algorithm. | ||
* | ||
* @return the name of the hash algorithm | ||
*/ | ||
String algorithm(); | ||
} |
Oops, something went wrong.