Symbol: use a dedicated hash function
since Symbol instance are now backed by a symbol table, we can use a much faster hash function by just hashing the pointer into the symbol table, since the Symbol string content is already checked at initialisation.
This commit is contained in:
parent
2204066a94
commit
baa4111358
2 changed files with 16 additions and 8 deletions
|
|
@ -95,18 +95,17 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
/** generating a hash value, e.g. for hashtables.
|
||||
This function is intended to be picked up by ADL,
|
||||
and should be usable both with \c std::tr1 and
|
||||
\c <boost/functional/hash.hpp> . It is implemented
|
||||
similar as the boost::hash specialisation for std::string */
|
||||
/** generate hash value based on the Literal's contents.
|
||||
* This function is intended to be picked up by ADL, and should be usable
|
||||
* both with `std::hash` and `<boost/functional/hash.hpp>`. It is implemented
|
||||
* similar as the boost::hash specialisation for std::string */
|
||||
size_t
|
||||
hash_value (Literal sym)
|
||||
hash_value (Literal literal)
|
||||
{
|
||||
size_t hash=0;
|
||||
if (sym)
|
||||
if (literal)
|
||||
{
|
||||
const char *pos = sym;
|
||||
const char *pos = literal;
|
||||
size_t maxpos = STRING_MAX_RELEVANT;
|
||||
for ( ; *pos && --maxpos; ++pos)
|
||||
hash_combine(hash, *pos);
|
||||
|
|
@ -115,6 +114,14 @@ namespace lib {
|
|||
return hash;
|
||||
}
|
||||
|
||||
/** hash value for Symbols is directly based on the symbol table entry */
|
||||
size_t
|
||||
hash_value (Symbol sym)
|
||||
{
|
||||
return sym? boost::hash_value (sym.c())
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace lib
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ namespace lib {
|
|||
/* ===== to be picked up by ADL ===== */
|
||||
|
||||
size_t hash_value (Literal);
|
||||
size_t hash_value (Symbol);
|
||||
|
||||
|
||||
/* === equality comparisons === */
|
||||
|
|
|
|||
Loading…
Reference in a new issue