2
0
mirror of https://github.com/boostorg/hash2.git synced 2026-01-19 04:12:12 +00:00

Add example/xxh128_from_xxh64.cpp

This commit is contained in:
Peter Dimov
2024-12-02 18:11:07 +02:00
parent 9e23d5d056
commit acfc309f72
3 changed files with 45 additions and 0 deletions

View File

@@ -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 ;

View File

@@ -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 <boost/hash2/xxhash.hpp>
#include <boost/hash2/digest.hpp>
#include <boost/endian/conversion.hpp>
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 <string>
#include <iostream>
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;
}

View File

@@ -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 ;