Skip to content

Commit

Permalink
checksum computation for xxh3
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Sep 4, 2023
1 parent 6ca6c73 commit 3943eef
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reference-implementations/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ komihash_5_7/komihash_5_7_checksum_config.cpp \
murmur3_32/murmur3_32_checksum_config.cpp \
murmur3_128/murmur3_128_checksum_config.cpp \
murmur3_128/smhasher/src/MurmurHash3.cpp \
xxh3/xxh3_checksum_config.cpp \
xxh3/xxHash/xxhash.c \
farmna.a \
farmuo.a \
-O2 -lssl -lcrypto -o calculate_checksums
2 changes: 2 additions & 0 deletions reference-implementations/calculate_checksums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "murmur3_32/murmur3_32_checksum_config.hpp"
#include "farmhash_na/farmhash_na_checksum_config.hpp"
#include "farmhash_uo/farmhash_uo_checksum_config.hpp"
#include "xxh3/xxh3_checksum_config.hpp"

using namespace std;

Expand Down Expand Up @@ -109,6 +110,7 @@ int main(int argc, char *argv[]) {
computeAndPrintChecksum<PolymurHash_2_0_ChecksumConfig>();
computeAndPrintChecksum<FarmHashNaChecksumConfig>();
computeAndPrintChecksum<FarmHashUoChecksumConfig>();
computeAndPrintChecksum<XXH3ChecksumConfig>();

return 0;
}
31 changes: 31 additions & 0 deletions reference-implementations/xxh3/xxh3_checksum_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2022-2023 Dynatrace LLC
*
* 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.
*/
#include "xxh3_checksum_config.hpp"
#include "xxhash/xxhash.h"
#include <cstring>

void XXH3ChecksumConfig::calculateHash(const uint8_t *seedBytes,
uint8_t *hashBytes, const uint8_t *dataBytes, uint64_t size) const {

uint64_t seed;
memcpy(&seed, seedBytes, 8);

uint64_t hash0 = XXH3_64bits((char*) (&dataBytes[0]), size);
uint64_t hash1 = XXH3_64bits_withSeed((char*) (&dataBytes[0]), size, seed);

memcpy(hashBytes, &hash0, 8);
memcpy(hashBytes + 8, &hash1, 8);
}
42 changes: 42 additions & 0 deletions reference-implementations/xxh3/xxh3_checksum_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2022-2023 Dynatrace LLC
*
* 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.
*/
#ifndef XXH3_CHECKSUM_CONFIG_HPP
#define XXH3_CHECKSUM_CONFIG_HPP

#include <string>

class XXH3ChecksumConfig {

public:

uint64_t getSeedSize() const {
return 8;
}

uint64_t getHashSize() const {
return 16;
}

std::string getName() const {
return "XXH3";
}

void calculateHash(const uint8_t *seedBytes, uint8_t *hashBytes,
const uint8_t *dataBytes, uint64_t size) const;

};

#endif // XXH3_CHECKSUM_CONFIG_HPP

0 comments on commit 3943eef

Please sign in to comment.