Skip to content

Commit

Permalink
std::hash jsoncons::string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 9, 2023
1 parent ae6ec02 commit 20402b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/jsoncons/detail/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ namespace std {
const int m = 1000000009;
size_t hash_value = 0;
size_t p_pow = 1;
for (char c : s) {
for (CharT c : s) {
hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
p_pow = (p_pow * p) % m;
}
Expand Down
15 changes: 15 additions & 0 deletions test/corelib/src/detail/string_view_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ TEST_CASE("string_view tests")
map.emplace(key1, 1);
map.emplace(key2, 2);

CHECK(map.find(key1) != map.end());
CHECK(map[key1] == 1);
CHECK(map.find(key2) != map.end());
CHECK(map[key2] == 2);
}
SECTION("test 2")
{
std::unordered_map<jsoncons::detail::wstring_view,int> map;

std::wstring key1{L"Foo"};
std::wstring key2{L"Bar"};

map.emplace(key1, 1);
map.emplace(key2, 2);

CHECK(map.find(key1) != map.end());
CHECK(map[key1] == 1);
CHECK(map.find(key2) != map.end());
Expand Down

0 comments on commit 20402b7

Please sign in to comment.