MCPcopy Create free account
hub / github.com/ByConity/ByConity / _Hash_bytes

Function _Hash_bytes

src/Common/StringUtils/StringUtils.cpp:131–174  ·  view source on GitHub ↗

Implementation of Murmur hash for 32-bit size_t.

Source from the content-addressed store, hash-verified

129
130 // Implementation of Murmur hash for 32-bit size_t.
131 size_t
132 _Hash_bytes(const void* ptr, size_t len, size_t seed)
133 {
134 const size_t m = 0x5bd1e995;
135 size_t hash = seed ^ len;
136 const char* buf = static_cast<const char*>(ptr);
137
138 // Mix 4 bytes at a time into the hash.
139 while(len >= 4)
140 {
141 size_t k = unaligned_load(buf);
142 k *= m;
143 k ^= k >> 24;
144 k *= m;
145 hash *= m;
146 hash ^= k;
147 buf += 4;
148 len -= 4;
149 }
150
151 size_t k;
152 // Handle the last few bytes of the input array.
153 switch(len)
154 {
155 case 3:
156 k = static_cast<unsigned char>(buf[2]);
157 hash ^= k << 16;
158 [[gnu::fallthrough]];
159 case 2:
160 k = static_cast<unsigned char>(buf[1]);
161 hash ^= k << 8;
162 [[gnu::fallthrough]];
163 case 1:
164 k = static_cast<unsigned char>(buf[0]);
165 hash ^= k;
166 hash *= m;
167 };
168
169 // Do a few final mixes of the hash.
170 hash ^= hash >> 13;
171 hash *= m;
172 hash ^= hash >> 15;
173 return hash;
174 }
175
176#elif __SIZEOF_SIZE_T__ == 8
177

Callers 1

hashImplFunction · 0.85

Calls 3

unaligned_loadFunction · 0.85
shift_mixFunction · 0.85
load_bytesFunction · 0.85

Tested by

no test coverage detected