Skip to content

Commit

Permalink
Add example/hash_without_seed.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Nov 28, 2024
1 parent f2077f4 commit 099b771
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ exe md5sum : md5sum.cpp ;
exe hash2sum : hash2sum.cpp ;
exe compile_time : compile_time.cpp ;
exe compile_time_2 : compile_time_2.cpp ;
exe hash_without_seed : hash_without_seed.cpp ;
29 changes: 29 additions & 0 deletions example/hash_without_seed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/siphash.hpp>
#include <boost/hash2/hash_append.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/unordered/unordered_flat_map.hpp>
#include <string>

template<class T, class H> class hash
{
public:

std::size_t operator()( T const& v ) const
{
H h;
boost::hash2::hash_append( h, {}, v );
return boost::hash2::get_integral_result<std::size_t>( h.result() );
}
};

int main()
{
boost::unordered_flat_map<std::string, int, hash<std::string, boost::hash2::siphash_64>> map;

map[ "foo" ] = 1;
map[ "bar" ] = 2;
}
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ link ../example/md5sum.cpp ;
link ../example/hash2sum.cpp : <cxxstd>11:<build>no <toolset>msvc-14.0:<build>no ;
link ../example/compile_time.cpp : <cxxstd>11:<build>no <toolset>msvc-14.0:<build>no ;
link ../example/compile_time_2.cpp : <cxxstd>11:<build>no <toolset>msvc-14.0:<build>no <toolset>gcc-5:<build>no ;
link ../example/hash_without_seed.cpp ;

0 comments on commit 099b771

Please sign in to comment.