Re: [boost] Re: [review] hash functions

In-Reply-To: <d17nlh$8o3$1@sea.gmane.org> daniel@calamity.org.uk (Daniel James) wrote (abridged):
I'm glad that I'm not the only person who's worried about alignment. But this is a problems for a cross-platform library. Either I'll have to introduce a load of macros to tweak it on various platforms (I'll need help there) or just accept it.
We can probably find something which gives reasonable results across a wide range of platforms. Shuffling the bits in a hash_combine-like manner would help. Eg something like: template <typename T> size_t hash_value( const T *p ) { size_t value = reinterpret_cast<size_t>(p); return value + value / sizeof(T); } If there's an easy way to turn sizeof(T) into a power of 2, use it. In many cases it will already be a power of 2, and I suspect the performance difference isn't crucial anyway. Alternatively we could just use: return value + (value >> 3); which ought to be reasonable for most small objects. It may also be reasonable for large objects that are heap-allocated, depending on how the heap is implemented. Anyway, I think it is better to do something like this than to just return value. -- Dave Harris, Nottingham, UK
participants (1)
-
brangdon@cix.compulink.co.uk