Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-11 10:53:18

Tobias Schwinger wrote:
> Example: let's say we have a disk-stored hash table and an in-memory
> hash table for caching. The same objects are stored but it is desirable to
> have two different hashing functions. Unfortunately boost::hash can
> only be used for at most one of them.
> If I wanted to implement double hashing I'ld have to duplicate the
> whole facility (which may include writing a lot of "hash_value2"
> functions for a grown project) because there can be only one 'hash_value'
> per type
> which can only use one algorithm for combining the hash values, as the
> current design does not provide a way to get parametrization in there.
> Looking at the source underlines this impression: hash_combine seems
> like a forgotten hard wired strategy in something that actually wants
> to be a facade.

The next generalization level isn't really about hash functions anymore. You
are asking for a generic visitation interface where you give a visitor to a
container (or a compound type with nonambiguous state*) and the container
applies the visitor to each of its elements. This facility is very useful
(not only for hashing, but for serialization, stream output, and others) but
I don't believe that it belongs in a utility hash function library.

(*) For some types, the choice what to visit (exact private representation,
virtual value representation, exact representation without transient state,
or something in between) may be nontrivial and depend on the overall context
in which the visitation occurs.

Boost list run by bdawes at, gregod at, cpdaniel at, john at