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 153e129 commit efe58be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions include/jsoncons/detail/string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,14 @@ namespace detail {

namespace std {
template<class CharT,class Traits>
struct std::hash<jsoncons::detail::basic_string_view<CharT, Traits>>
struct hash<jsoncons::detail::basic_string_view<CharT, Traits>>
{
std::size_t operator()(const jsoncons::detail::basic_string_view<CharT, Traits>& s) const noexcept
size_t operator()(const jsoncons::detail::basic_string_view<CharT, Traits>& 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;
Expand Down
20 changes: 10 additions & 10 deletions include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ namespace detail {
};

template <class Json,class JsonReference = const Json&, class TempAllocator=std::allocator<char>>
class update_expression
class jsonpath_expr
{
public:
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, JsonReference>;
Expand All @@ -2628,7 +2628,7 @@ namespace detail {
std::unique_ptr<jsoncons::jsonpath::detail::static_resources<value_type,reference>> static_resources_;
path_expression_type expr_;
public:
update_expression(const allocator_set<allocator_type,TempAllocator>& alloc_set,
jsonpath_expr(const allocator_set<allocator_type,TempAllocator>& alloc_set,
std::unique_ptr<jsoncons::jsonpath::detail::static_resources<value_type,reference>>&& resources,
path_expression_type&& expr)
: alloc_(alloc_set.get_allocator()),
Expand All @@ -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 <class BinaryCallback>
typename std::enable_if<extension_traits::is_binary_function_object<BinaryCallback,const json_location_type&,const_reference>::value,void>::type
Expand Down Expand Up @@ -2751,7 +2751,7 @@ namespace detail {
}

template <class Json>
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<typename jsonpath_traits<Json>::value_type>& funcs = jsoncons::jsonpath::custom_functions<typename jsonpath_traits<Json>::value_type>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json>;
Expand All @@ -2764,11 +2764,11 @@ namespace detail {
evaluator_type evaluator;
auto expr = evaluator.compile(*static_resources, path);

return jsoncons::jsonpath::update_expression<value_type,reference>(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr));
return jsoncons::jsonpath::jsonpath_expr<value_type,reference>(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr));
}

template <class Json, class TempAllocator>
auto make_update_expression(const allocator_set<typename Json::allocator_type,TempAllocator>& alloc_set,
auto make_jsonpath_expr(const allocator_set<typename Json::allocator_type,TempAllocator>& alloc_set,
const typename Json::string_view_type& path,
const jsoncons::jsonpath::custom_functions<typename jsonpath_traits<Json>::value_type>& funcs, std::error_code& ec)
{
Expand All @@ -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<value_type,reference>(alloc_set, std::move(static_resources), std::move(expr));
return jsoncons::jsonpath::jsonpath_expr<value_type,reference>(alloc_set, std::move(static_resources), std::move(expr));
}

} // namespace jsonpath
Expand Down
4 changes: 2 additions & 2 deletions test/jsonpath/src/jsonpath_make_expression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST_CASE("jsonpath make_expression test")

const json doc = json::parse(input);

auto expr = jsoncons::jsonpath::make_update_expression<const json>("$.books[*]");
auto expr = jsoncons::jsonpath::make_jsonpath_expr<const json>("$.books[*]");

auto callback = [&](const jsonpath::json_location& /*location*/, const json& book)
{
Expand All @@ -80,7 +80,7 @@ TEST_CASE("jsonpath make_expression test")

json doc = json::parse(input);

auto expr = jsoncons::jsonpath::make_update_expression<json>("$.books[*]");
auto expr = jsoncons::jsonpath::make_jsonpath_expr<json>("$.books[*]");

auto callback1 = [&](const jsonpath::json_location& /*location*/, const json& book)
{
Expand Down

0 comments on commit efe58be

Please sign in to comment.