Change type of hash to guaranteed 64 bit integer
Fixes #66, closes #69 (obsolete now).
This commit is contained in:
parent
758f26afce
commit
3cd14ca0f5
1 changed files with 8 additions and 6 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef CPPAST_CPP_ENTITY_INDEX_HPP_INCLUDED
|
#ifndef CPPAST_CPP_ENTITY_INDEX_HPP_INCLUDED
|
||||||
#define CPPAST_CPP_ENTITY_INDEX_HPP_INCLUDED
|
#define CPPAST_CPP_ENTITY_INDEX_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
@ -23,20 +24,21 @@ class cpp_namespace;
|
||||||
/// \exclude
|
/// \exclude
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
constexpr std::size_t fnv_basis = 14695981039346656037ull;
|
using hash_type = std::uint_least64_t;
|
||||||
constexpr std::size_t fnv_prime = 1099511628211ull;
|
constexpr hash_type fnv_basis = 14695981039346656037ull;
|
||||||
|
constexpr hash_type fnv_prime = 1099511628211ull;
|
||||||
|
|
||||||
// FNV-1a 64 bit hash
|
// FNV-1a 64 bit hash
|
||||||
constexpr std::size_t id_hash(const char* str, std::size_t hash = fnv_basis)
|
constexpr hash_type id_hash(const char* str, hash_type hash = fnv_basis)
|
||||||
{
|
{
|
||||||
return *str ? id_hash(str + 1, (hash ^ std::size_t(*str)) * fnv_prime) : hash;
|
return *str ? id_hash(str + 1, (hash ^ hash_type(*str)) * fnv_prime) : hash;
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
/// A [ts::strong_typedef]() representing the unique id of a [cppast::cpp_entity]().
|
/// A [ts::strong_typedef]() representing the unique id of a [cppast::cpp_entity]().
|
||||||
///
|
///
|
||||||
/// It is comparable for equality.
|
/// It is comparable for equality.
|
||||||
struct cpp_entity_id : type_safe::strong_typedef<cpp_entity_id, std::size_t>,
|
struct cpp_entity_id : type_safe::strong_typedef<cpp_entity_id, detail::hash_type>,
|
||||||
type_safe::strong_typedef_op::equality_comparison<cpp_entity_id>
|
type_safe::strong_typedef_op::equality_comparison<cpp_entity_id>
|
||||||
{
|
{
|
||||||
explicit cpp_entity_id(const std::string& str) : cpp_entity_id(str.c_str()) {}
|
explicit cpp_entity_id(const std::string& str) : cpp_entity_id(str.c_str()) {}
|
||||||
|
|
@ -118,7 +120,7 @@ private:
|
||||||
{
|
{
|
||||||
std::size_t operator()(const cpp_entity_id& id) const noexcept
|
std::size_t operator()(const cpp_entity_id& id) const noexcept
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(id);
|
return std::size_t(static_cast<detail::hash_type>(id));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue