除以sizeof(void*)意味着什么?

ann*_*ist 8 c++ hash sizeof void-pointers

我正在使用哈希表,我遇到了这个函数.但是hash/sizeof(void*)是什么意思?和之后给出的评论 - 摆脱已知的0位?

// This matches when the hashtable key is a pointer.
      template<class HashKey> class hash_munger<HashKey*> {
       public:
        static size_t MungedHash(size_t hash) {
          // TODO(csilvers): consider rotating instead:
          //    static const int shift = (sizeof(void *) == 4) ? 2 : 3;
          //    return (hash << (sizeof(hash) * 8) - shift)) | (hash >> shift);
          // This matters if we ever change sparse/dense_hash_* to compare
          // hashes before comparing actual values.  It's speedy on x86.
          return hash / sizeof(void*);   // get rid of known-0 bits
        }
      };
Run Code Online (Sandbox Code Playgroud)

Bas*_*tch 9

在大多数机器和ABI上,指针通常是字对齐的.因此,除以sizeof指针基本上忽略了最小位(例如,在大多数64位处理器上,3个字节地址的最低位为0,因为64位字具有8个字节,每个8位).