Lumiera  0.pre.03
»edit your freedom«
lib::idi::anonymous_namespace{entry-id.hpp} Namespace Reference

Functions

LuidH buildHash (string const &sym, HashVal seed=0)
 build up a hash value, packaged as LUID. More...
 

Variables

const size_t KNUTH_MAGIC = 2654435761
 lousy old tinkerer's trick: hash values with poor distribution can be improved by spreading the input with something close to the golden ratio. More...
 

Function Documentation

◆ buildHash()

LuidH lib::idi::anonymous_namespace{entry-id.hpp}::buildHash ( string const &  sym,
HashVal  seed = 0 
)
inline

build up a hash value, packaged as LUID.

Parameters
symsymbolic ID-string to be hashed
seed(optional) hash value to combine with the sym.
Note
This is a half baked preliminary solution. The issue here is that LUID has a fixed size of 128bit, whereas the hash values of the std library (and boost) have the smaller and platform dependent type of size_t. This hack here assumes that size_t corresponds to void*, which is correct for i386 and AMD64. LUID provides a hook for embedding a void* (setting the trailing bits to zero). Finally we reinterpret the char[] of the LUID as a LuidH class, which is ugly, but granted to work.
Todo:
several unsolved design problems. How to deal with std hash values in conjunction with LUID. How to create a LuidH instance, if not generating a new random value. How to make EntryID and asset::Ident interchangeable, /////////TICKET #739 which would require both to yield the same hash values....
Warning
there is a weakness in boost::hash for strings of running numbers, causing collisions already for a small set with less than 100000 entries. To mitigate the problem, we hash in the trailing digits, and spread them by the KNUTH_MAGIC /////////TICKET #865
this code isn't portable and breaks if sizeof(size_t) < sizeof(void*)
See also
HashGenerator_test::verify_Knuth_workaround

Definition at line 117 of file entry-id.hpp.

References lumiera_uid_set_ptr().

Referenced by EntryID< StreamType >::canRecast().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ KNUTH_MAGIC

const size_t KNUTH_MAGIC = 2654435761

lousy old tinkerer's trick: hash values with poor distribution can be improved by spreading the input with something close to the golden ratio.

Additionally, the scaling factor (for hashing) should be prime. 2^32 * (√5-1)/2 = 2654435769.49723

Definition at line 92 of file entry-id.hpp.

Referenced by HashGenerator_test::verify_Knuth_workaround().