From efe58be90b47bf36aa9c2211cfc2a4c97740a597 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Thu, 9 Nov 2023 12:54:20 -0500 Subject: [PATCH] std::hash jsoncons::string_view --- include/jsoncons/detail/string_view.hpp | 8 ++++---- .../jsonpath/jsonpath_expression.hpp | 20 +++++++++---------- .../src/jsonpath_make_expression_tests.cpp | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/jsoncons/detail/string_view.hpp b/include/jsoncons/detail/string_view.hpp index 61eff0086f..4836ee9ca3 100644 --- a/include/jsoncons/detail/string_view.hpp +++ b/include/jsoncons/detail/string_view.hpp @@ -539,14 +539,14 @@ namespace detail { namespace std { template - struct std::hash> + struct hash> { - std::size_t operator()(const jsoncons::detail::basic_string_view& s) const noexcept + size_t operator()(const jsoncons::detail::basic_string_view& s) const noexcept { const int p = 53; const int m = 1000000009; - std::size_t hash_value = 0; - std::size_t p_pow = 1; + size_t hash_value = 0; + size_t p_pow = 1; for (char c : s) { hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m; p_pow = (p_pow * p) % m; diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index ab5f6788a3..4120a155b6 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -2608,7 +2608,7 @@ namespace detail { }; template > - class update_expression + class jsonpath_expr { public: using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits; @@ -2628,7 +2628,7 @@ namespace detail { std::unique_ptr> static_resources_; path_expression_type expr_; public: - update_expression(const allocator_set& alloc_set, + jsonpath_expr(const allocator_set& alloc_set, std::unique_ptr>&& resources, path_expression_type&& expr) : alloc_(alloc_set.get_allocator()), @@ -2637,11 +2637,11 @@ namespace detail { { } - update_expression(const update_expression&) = delete; - update_expression(update_expression&&) = default; + jsonpath_expr(const jsonpath_expr&) = delete; + jsonpath_expr(jsonpath_expr&&) = default; - update_expression& operator=(const update_expression&) = delete; - update_expression& operator=(update_expression&&) = default; + jsonpath_expr& operator=(const jsonpath_expr&) = delete; + jsonpath_expr& operator=(jsonpath_expr&&) = default; template typename std::enable_if::value,void>::type @@ -2751,7 +2751,7 @@ namespace detail { } template - auto make_update_expression(const typename Json::string_view_type& path, + auto make_jsonpath_expr(const typename Json::string_view_type& path, const jsoncons::jsonpath::custom_functions::value_type>& funcs = jsoncons::jsonpath::custom_functions::value_type>()) { using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits; @@ -2764,11 +2764,11 @@ namespace detail { evaluator_type evaluator; auto expr = evaluator.compile(*static_resources, path); - return jsoncons::jsonpath::update_expression(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr)); + return jsoncons::jsonpath::jsonpath_expr(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr)); } template - auto make_update_expression(const allocator_set& alloc_set, + auto make_jsonpath_expr(const allocator_set& alloc_set, const typename Json::string_view_type& path, const jsoncons::jsonpath::custom_functions::value_type>& funcs, std::error_code& ec) { @@ -2783,7 +2783,7 @@ namespace detail { evaluator_type evaluator{alloc_set.get_allocator()}; auto expr = evaluator.compile(*static_resources, path, ec); - return jsoncons::jsonpath::update_expression(alloc_set, std::move(static_resources), std::move(expr)); + return jsoncons::jsonpath::jsonpath_expr(alloc_set, std::move(static_resources), std::move(expr)); } } // namespace jsonpath diff --git a/test/jsonpath/src/jsonpath_make_expression_tests.cpp b/test/jsonpath/src/jsonpath_make_expression_tests.cpp index 66adab38e9..b45267d0d9 100644 --- a/test/jsonpath/src/jsonpath_make_expression_tests.cpp +++ b/test/jsonpath/src/jsonpath_make_expression_tests.cpp @@ -58,7 +58,7 @@ TEST_CASE("jsonpath make_expression test") const json doc = json::parse(input); - auto expr = jsoncons::jsonpath::make_update_expression("$.books[*]"); + auto expr = jsoncons::jsonpath::make_jsonpath_expr("$.books[*]"); auto callback = [&](const jsonpath::json_location& /*location*/, const json& book) { @@ -80,7 +80,7 @@ TEST_CASE("jsonpath make_expression test") json doc = json::parse(input); - auto expr = jsoncons::jsonpath::make_update_expression("$.books[*]"); + auto expr = jsoncons::jsonpath::make_jsonpath_expr("$.books[*]"); auto callback1 = [&](const jsonpath::json_location& /*location*/, const json& book) {