microsoft/onnxruntime-extensions
Publicmirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable
cmake/externals/farmhash/dev/TESTBOILERPLATEHash32
22lines · modecode
| 1 | // Hash the concatenation of the given string with itself. |
| 2 | uint32_t Hash32D(const char* s, size_t len) { |
| 3 | char buf[8000]; |
| 4 | char* ss = len*2 > sizeof(buf) ? (char*)malloc(len*2) : buf; |
| 5 | memcpy(ss, s, len); |
| 6 | memcpy(ss + len, s, len); |
| 7 | uint32_t h = Hash32(ss, len*2); |
| 8 | if (ss != buf) free(ss); |
| 9 | return h; |
| 10 | } |
| 11 | |
| 12 | // Hash the concatenation of the given string with 3 copies of itself. |
| 13 | uint32_t Hash32Q(const char* s, size_t len) { |
| 14 | char buf[8000]; |
| 15 | char* ss = len*4 > sizeof(buf) ? (char*)malloc(len*4) : buf; |
| 16 | memcpy(ss, s, len); |
| 17 | memcpy(ss + len, s, len); |
| 18 | memcpy(ss + len*2, ss, len*2); |
| 19 | uint32_t h = Hash32(ss, len*4); |
| 20 | if (ss != buf) free(ss); |
| 21 | return h; |
| 22 | } |