From acfc309f727deacfcea9db90a4f3ff25efa03ee4 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 2 Dec 2024 18:11:07 +0200 Subject: [PATCH] Add example/xxh128_from_xxh64.cpp --- example/Jamfile | 1 + example/xxh128_from_xxh64.cpp | 43 +++++++++++++++++++++++++++++++++++ test/Jamfile | 1 + 3 files changed, 45 insertions(+) create mode 100644 example/xxh128_from_xxh64.cpp diff --git a/example/Jamfile b/example/Jamfile index ad7bae3..1b7cde0 100644 --- a/example/Jamfile +++ b/example/Jamfile @@ -12,3 +12,4 @@ exe hash_with_uint64_seed : hash_with_uint64_seed.cpp ; exe hash_with_byte_seed : hash_with_byte_seed.cpp ; exe hash_with_any_seed : hash_with_any_seed.cpp ; exe hash_32_64 : hash_32_64.cpp ; +exe xxh128_from_xxh64 : xxh128_from_xxh64.cpp ; diff --git a/example/xxh128_from_xxh64.cpp b/example/xxh128_from_xxh64.cpp new file mode 100644 index 0000000..1f42df2 --- /dev/null +++ b/example/xxh128_from_xxh64.cpp @@ -0,0 +1,43 @@ +// Copyright 2024 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +class xxhash_128: private boost::hash2::xxhash_64 +{ +public: + + using result_type = boost::hash2::digest<16>; + + using xxhash_64::xxhash_64; + using xxhash_64::update; + + result_type result() + { + std::uint64_t r1 = xxhash_64::result(); + std::uint64_t r2 = xxhash_64::result(); + + result_type r = {}; + + boost::endian::store_little_u64( r.data() + 0, r1 ); + boost::endian::store_little_u64( r.data() + 8, r2 ); + + return r; + } +}; + +#include +#include + +int main() +{ + std::string tv( "The quick brown fox jumps over the lazy dog" ); + + xxhash_128 hash( 43 ); + hash.update( tv.data(), tv.size() ); + + std::cout << hash.result() << std::endl; +} diff --git a/test/Jamfile b/test/Jamfile index 6e42979..d177d1c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -170,3 +170,4 @@ link ../example/hash_with_uint64_seed.cpp ; link ../example/hash_with_byte_seed.cpp ; link ../example/hash_with_any_seed.cpp ; link ../example/hash_32_64.cpp ; +link ../example/xxh128_from_xxh64.cpp ;