xenium
List of all members
xenium::hash< Key * > Struct Template Reference

Specialized hash functor for pointer types to get rid of the alignment. More...

#include <hash.hpp>

Detailed Description

template<class Key>
struct xenium::hash< Key * >

Specialized hash functor for pointer types to get rid of the alignment.

Pointers are usually aligned, with the alignment depending on the type they point to. This means that the lower bits of the pointer are zero. Many hash maps calculate the bucket index using a modulo by a power of two, because this is simply a logical and operation. However, by using this approach with aligned pointers the lower buckets never get populated. To avoid this problem and achieve a better distribution in such hash maps, this specialization shifts the size_t representation of the pointer to the right by X bits, where X is calculated based on the alignment of Key.