Skip to content

Commit

Permalink
Switch Flavor::size_type for the predefined flavors to std::uint64_t;…
Browse files Browse the repository at this point in the history
… if we at some point need to append a foreign size_t hash, e.g. from std::hash<T>, we need to not throw away information
  • Loading branch information
pdimov committed Nov 9, 2024
1 parent d29780f commit 877f6c9
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions include/boost/hash2/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ namespace hash2

struct default_flavor
{
using size_type = std::uint32_t;
using size_type = std::uint64_t;
static constexpr auto byte_order = endian::native;
};

struct little_endian_flavor
{
using size_type = std::uint32_t;
using size_type = std::uint64_t;
static constexpr auto byte_order = endian::little;
};

struct big_endian_flavor
{
using size_type = std::uint32_t;
using size_type = std::uint64_t;
static constexpr auto byte_order = endian::big;
};

Expand Down
12 changes: 6 additions & 6 deletions test/append_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor, unsigned char>( 2227238665 );
test<fnv1a_32, big_endian_flavor, unsigned char>( 3245468929 );
test<fnv1a_32, little_endian_flavor, unsigned char>( 2468847257 );
test<fnv1a_32, big_endian_flavor, unsigned char>( 78451921 );

test<fnv1a_32, little_endian_flavor, int>( 1745310485 );
test<fnv1a_32, big_endian_flavor, int>( 3959736277 );
test<fnv1a_32, little_endian_flavor, int>( 2374676325 );
test<fnv1a_32, big_endian_flavor, int>( 2877134693 );

test<fnv1a_32, little_endian_flavor, double>( 1949716516 );
test<fnv1a_32, big_endian_flavor, double>( 2651227990 );
test<fnv1a_32, little_endian_flavor, double>( 461647460 );
test<fnv1a_32, big_endian_flavor, double>( 1394753398 );

return boost::report_errors();
}
4 changes: 2 additions & 2 deletions test/append_described_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor>( {}, 1388033884 );
test<fnv1a_32, big_endian_flavor>( {}, 3611226160 );
test<fnv1a_32, little_endian_flavor>( {}, 2447527756 );
test<fnv1a_32, big_endian_flavor>( {}, 2986383648 );

return boost::report_errors();
}
Expand Down
16 changes: 8 additions & 8 deletions test/append_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ int main()
{
using namespace boost::hash2;

test< fnv1a_32, little_endian_flavor, std::map<int, int> >( 3152726101ul );
test< fnv1a_64, little_endian_flavor, std::map<int, int> >( 11386405661620022965ull );
test< fnv1a_32, little_endian_flavor, std::map<int, int> >( 1082144933ul );
test< fnv1a_64, little_endian_flavor, std::map<int, int> >( 12051529320333828229ull );

test< fnv1a_32, little_endian_flavor, std::multimap<int, int> >( 3152726101ul );
test< fnv1a_64, little_endian_flavor, std::multimap<int, int> >( 11386405661620022965ull );
test< fnv1a_32, little_endian_flavor, std::multimap<int, int> >( 1082144933ul );
test< fnv1a_64, little_endian_flavor, std::multimap<int, int> >( 12051529320333828229ull );

test< fnv1a_32, little_endian_flavor, std::unordered_map<int, int> >( 2742410178ul );
test< fnv1a_64, little_endian_flavor, std::unordered_map<int, int> >( 7026041901235387186ull );
test< fnv1a_32, little_endian_flavor, std::unordered_map<int, int> >( 1094735330ul );
test< fnv1a_64, little_endian_flavor, std::unordered_map<int, int> >( 2617313294186790738ull );

test< fnv1a_32, little_endian_flavor, std::unordered_multimap<int, int> >( 2742410178ul );
test< fnv1a_64, little_endian_flavor, std::unordered_multimap<int, int> >( 7026041901235387186ull );
test< fnv1a_32, little_endian_flavor, std::unordered_multimap<int, int> >( 1094735330ul );
test< fnv1a_64, little_endian_flavor, std::unordered_multimap<int, int> >( 2617313294186790738ull );

return boost::report_errors();
}
16 changes: 8 additions & 8 deletions test/append_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ int main()
{
using namespace boost::hash2;

test< fnv1a_32, little_endian_flavor, std::set<int> >( 2078558933ul );
test< fnv1a_64, little_endian_flavor, std::set<int> >( 6271229243378528309ull );
test< fnv1a_32, little_endian_flavor, std::set<int> >( 3576652581ul );
test< fnv1a_64, little_endian_flavor, std::set<int> >( 17046016161958689285ull );

test< fnv1a_32, little_endian_flavor, std::multiset<int> >( 2078558933ul );
test< fnv1a_64, little_endian_flavor, std::multiset<int> >( 6271229243378528309ull );
test< fnv1a_32, little_endian_flavor, std::multiset<int> >( 3576652581ul );
test< fnv1a_64, little_endian_flavor, std::multiset<int> >( 17046016161958689285ull );

test< fnv1a_32, little_endian_flavor, std::unordered_set<int> >( 2270492092ul );
test< fnv1a_64, little_endian_flavor, std::unordered_set<int> >( 2830007867253608057ull );
test< fnv1a_32, little_endian_flavor, std::unordered_set<int> >( 3782055292ul );
test< fnv1a_64, little_endian_flavor, std::unordered_set<int> >( 3232503781718511241ull );

test< fnv1a_32, little_endian_flavor, std::unordered_multiset<int> >( 2270492092ul );
test< fnv1a_64, little_endian_flavor, std::unordered_multiset<int> >( 2830007867253608057ull );
test< fnv1a_32, little_endian_flavor, std::unordered_multiset<int> >( 3782055292ul );
test< fnv1a_64, little_endian_flavor, std::unordered_multiset<int> >( 3232503781718511241ull );

return boost::report_errors();
}
16 changes: 8 additions & 8 deletions test/append_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor, char>( 2227238665 );
test<fnv1a_32, big_endian_flavor, char>( 3245468929 );
test<fnv1a_32, little_endian_flavor, char>( 2468847257 );
test<fnv1a_32, big_endian_flavor, char>( 78451921 );

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L

test<fnv1a_32, little_endian_flavor, char8_t>( 2227238665 );
test<fnv1a_32, big_endian_flavor, char8_t>( 3245468929 );
test<fnv1a_32, little_endian_flavor, char8_t>( 2468847257 );
test<fnv1a_32, big_endian_flavor, char8_t>( 78451921 );

#endif

test<fnv1a_32, little_endian_flavor, char16_t>( 2981571797 );
test<fnv1a_32, big_endian_flavor, char16_t>( 1063054677 );
test<fnv1a_32, little_endian_flavor, char16_t>( 634283301 );
test<fnv1a_32, big_endian_flavor, char16_t>( 1469224165 );

test<fnv1a_32, little_endian_flavor, char32_t>( 1745310485 );
test<fnv1a_32, big_endian_flavor, char32_t>( 3959736277 );
test<fnv1a_32, little_endian_flavor, char32_t>( 2374676325 );
test<fnv1a_32, big_endian_flavor, char32_t>( 2877134693 );

return boost::report_errors();
}
16 changes: 8 additions & 8 deletions test/append_string_cx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ int main()
{
using namespace boost::hash2;

TEST_EQ( (test<fnv1a_32, little_endian_flavor, char>()), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char>()), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, char>()), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char>()), 78451921 );

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L

TEST_EQ( (test<fnv1a_32, little_endian_flavor, char8_t>()), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char8_t>()), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, char8_t>()), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char8_t>()), 78451921 );

#endif

TEST_EQ( (test<fnv1a_32, little_endian_flavor, char16_t>()), 2981571797 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char16_t>()), 1063054677 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, char16_t>()), 634283301 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char16_t>()), 1469224165 );

TEST_EQ( (test<fnv1a_32, little_endian_flavor, char32_t>()), 1745310485 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char32_t>()), 3959736277 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, char32_t>()), 2374676325 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, char32_t>()), 2877134693 );

return boost::report_errors();
}
16 changes: 8 additions & 8 deletions test/append_string_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor, char>( 2227238665 );
test<fnv1a_32, big_endian_flavor, char>( 3245468929 );
test<fnv1a_32, little_endian_flavor, char>( 2468847257 );
test<fnv1a_32, big_endian_flavor, char>( 78451921 );

#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L

test<fnv1a_32, little_endian_flavor, char8_t>( 2227238665 );
test<fnv1a_32, big_endian_flavor, char8_t>( 3245468929 );
test<fnv1a_32, little_endian_flavor, char8_t>( 2468847257 );
test<fnv1a_32, big_endian_flavor, char8_t>( 78451921 );

#endif

test<fnv1a_32, little_endian_flavor, char16_t>( 2981571797 );
test<fnv1a_32, big_endian_flavor, char16_t>( 1063054677 );
test<fnv1a_32, little_endian_flavor, char16_t>( 634283301 );
test<fnv1a_32, big_endian_flavor, char16_t>( 1469224165 );

test<fnv1a_32, little_endian_flavor, char32_t>( 1745310485 );
test<fnv1a_32, big_endian_flavor, char32_t>( 3959736277 );
test<fnv1a_32, little_endian_flavor, char32_t>( 2374676325 );
test<fnv1a_32, big_endian_flavor, char32_t>( 2877134693 );

return boost::report_errors();
}
12 changes: 6 additions & 6 deletions test/append_string_view_cx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ int main()

constexpr char const* str = "\x01\x02\x03\x04";

TEST_EQ( (test<fnv1a_32, little_endian_flavor>( boost::string_view( str, 4 ) )), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( boost::string_view( str, 4 ) )), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor>( boost::string_view( str, 4 ) )), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( boost::string_view( str, 4 ) )), 78451921 );

TEST_EQ( (test<fnv1a_32, little_endian_flavor>( boost::core::string_view( str, 4 ) )), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( boost::core::string_view( str, 4 ) )), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor>( boost::core::string_view( str, 4 ) )), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( boost::core::string_view( str, 4 ) )), 78451921 );

#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)

TEST_EQ( (test<fnv1a_32, little_endian_flavor>( std::string_view( str ) )), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( std::string_view( str ) )), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor>( std::string_view( str ) )), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor>( std::string_view( str ) )), 78451921 );

#endif

Expand Down
4 changes: 2 additions & 2 deletions test/append_tag_invoke_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor>( {}, 1388033884 );
test<fnv1a_32, big_endian_flavor>( {}, 3611226160 );
test<fnv1a_32, little_endian_flavor>( {}, 2447527756 );
test<fnv1a_32, big_endian_flavor>( {}, 2986383648 );

return boost::report_errors();
}
4 changes: 2 additions & 2 deletions test/append_tag_invoke_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int main()
{
using namespace boost::hash2;

test<fnv1a_32, little_endian_flavor>( {}, 1388033884 );
test<fnv1a_32, big_endian_flavor>( {}, 3611226160 );
test<fnv1a_32, little_endian_flavor>( {}, 2447527756 );
test<fnv1a_32, big_endian_flavor>( {}, 2986383648 );

return boost::report_errors();
}
12 changes: 6 additions & 6 deletions test/append_vector_cx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ int main()
{
using namespace boost::hash2;

TEST_EQ( (test<fnv1a_32, little_endian_flavor, unsigned char>()), 2227238665 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, unsigned char>()), 3245468929 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, unsigned char>()), 2468847257 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, unsigned char>()), 78451921 );

TEST_EQ( (test<fnv1a_32, little_endian_flavor, int>()), 1745310485 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, int>()), 3959736277 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, int>()), 2374676325 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, int>()), 2877134693 );

TEST_EQ( (test<fnv1a_32, little_endian_flavor, double>()), 1949716516 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, double>()), 2651227990 );
TEST_EQ( (test<fnv1a_32, little_endian_flavor, double>()), 461647460 );
TEST_EQ( (test<fnv1a_32, big_endian_flavor, double>()), 1394753398 );

return boost::report_errors();
}
6 changes: 3 additions & 3 deletions test/flavor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ int main()
{
using namespace boost::hash2;

BOOST_TEST_TRAIT_SAME( default_flavor::size_type, std::uint32_t );
BOOST_TEST_TRAIT_SAME( default_flavor::size_type, std::uint64_t );
BOOST_TEST( default_flavor::byte_order == endian::native );

BOOST_TEST_TRAIT_SAME( little_endian_flavor::size_type, std::uint32_t );
BOOST_TEST_TRAIT_SAME( little_endian_flavor::size_type, std::uint64_t );
BOOST_TEST( little_endian_flavor::byte_order == endian::little );

BOOST_TEST_TRAIT_SAME( big_endian_flavor::size_type, std::uint32_t );
BOOST_TEST_TRAIT_SAME( big_endian_flavor::size_type, std::uint64_t );
BOOST_TEST( big_endian_flavor::byte_order == endian::big );

return boost::report_errors();
Expand Down
4 changes: 2 additions & 2 deletions test/hash_append_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ template<class Hash, class Flavor, class R> void test( R r )

int main()
{
test<boost::hash2::fnv1a_32, boost::hash2::little_endian_flavor>( 2425039999ul );
test<lib2::fnv1a, boost::hash2::little_endian_flavor>( 2425039999ul );
test<boost::hash2::fnv1a_32, boost::hash2::little_endian_flavor>( 4058687743ul );
test<lib2::fnv1a, boost::hash2::little_endian_flavor>( 4058687743ul );

return boost::report_errors();
}

0 comments on commit 877f6c9

Please sign in to comment.