ATLAS Offline Software
Public Member Functions | List of all members
SG::ptrhash Struct Reference

Improved hash function for pointers. More...

#include <ptrhash.h>

Collaboration diagram for SG::ptrhash:

Public Member Functions

std::size_t operator() (const void *p) const
 

Detailed Description

Improved hash function for pointers.

The default hash function for pointers used by unordered_map and friends is just the result of casting the pointer to an int. The problem is that most pointers one deals with are going to be aligned; if the pointers are to objects obtained through malloc, then on all systems we deal with, at least the lower three bits of the pointer will always be clear. Since unordered_map uses a bucket-hash scheme, this means that only 1/8 of the buckets will be used in such a case, resulting in lower efficiency.

Here, we try to avoid this problem.

Definition at line 40 of file ptrhash.h.

Member Function Documentation

◆ operator()()

std::size_t SG::ptrhash::operator() ( const void *  p) const
inline

Definition at line 42 of file ptrhash.h.

43  {
44  std::size_t x = reinterpret_cast<std::size_t> (p);
45  return (x>>3) ^ (x&7);
46  }

The documentation for this struct was generated from the following file:
x
#define x
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210