mapnik::value - revive hash_value function implementation (#2358)
This commit is contained in:
parent
b415549823
commit
454a69c582
4 changed files with 87 additions and 2 deletions
|
@ -50,9 +50,12 @@ private:
|
|||
}
|
||||
|
||||
namespace U_ICU_NAMESPACE {
|
||||
inline std::size_t hash_value(mapnik::value_unicode_string const& val) {
|
||||
|
||||
inline std::size_t hash_value(mapnik::value_unicode_string const& val)
|
||||
{
|
||||
return val.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MAPNIK_UNICODE_HPP
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/value_hash.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
@ -980,6 +981,12 @@ inline bool value::is_null() const
|
|||
return util::apply_visitor(mapnik::detail::is_null_visitor(), base_);
|
||||
}
|
||||
|
||||
// hash function
|
||||
inline std::size_t hash_value(value const& val)
|
||||
{
|
||||
return hash_value(val.base());
|
||||
}
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_VALUE_HPP
|
||||
|
|
74
include/mapnik/value_hash.hpp
Normal file
74
include/mapnik/value_hash.hpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_VALUE_HASH_HPP
|
||||
#define MAPNIK_VALUE_HASH_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
// stl
|
||||
#include <functional>
|
||||
|
||||
namespace mapnik { namespace detail {
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(std::size_t & seed, T const& v)
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
||||
}
|
||||
|
||||
struct value_hasher: public util::static_visitor<std::size_t>
|
||||
{
|
||||
std::size_t operator() (value_null val) const
|
||||
{
|
||||
return hash_value(val);
|
||||
}
|
||||
|
||||
std::size_t operator() (value_unicode_string const& val) const
|
||||
{
|
||||
return hash_value(val);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::size_t operator()(T const& val) const
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
return hasher(val);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
std::size_t hash_value(T const& val)
|
||||
{
|
||||
std::size_t seed = util::apply_visitor(detail::value_hasher(), val);
|
||||
detail::hash_combine(seed, val.get_type_index());
|
||||
return seed;
|
||||
}
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_VALUE_HASH_HPP
|
|
@ -112,7 +112,8 @@ inline std::size_t hash_value(value_null const&)
|
|||
}
|
||||
|
||||
template <typename TChar, typename TTraits>
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, value_null const& v) {
|
||||
inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, value_null const& v)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue