| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #include "hash.h" | 
| 2 |  |  |  |  |  |  | #include | 
| 3 |  |  |  |  |  |  | #include | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | namespace panda { namespace hash { | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 101 |  |  |  |  |  | uint64_t hash_murmur64a (const char* str, size_t len) { | 
| 8 | 101 |  |  |  |  |  | const uint64_t seed = 7; | 
| 9 | 101 |  |  |  |  |  | const uint64_t m = 0xc6a4a7935bd1e995LLU; | 
| 10 | 101 |  |  |  |  |  | const int r = 47; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 101 |  |  |  |  |  | const uint64_t * data = (const uint64_t *) str; | 
| 13 | 101 |  |  |  |  |  | const uint64_t * end = data + (len/8); | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 101 |  |  |  |  |  | uint64_t h = seed ^ (len * m); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1315 | 100 |  |  |  |  | while (data != end) { | 
| 18 | 1214 |  |  |  |  |  | uint64_t k = *data++; | 
| 19 | 1214 |  |  |  |  |  | k *= m; | 
| 20 | 1214 |  |  |  |  |  | k ^= k >> r; | 
| 21 | 1214 |  |  |  |  |  | k *= m; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 1214 |  |  |  |  |  | h ^= k; | 
| 24 | 1214 |  |  |  |  |  | h *= m; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 101 |  |  |  |  |  | const unsigned char * data2 = (const unsigned char*) data; | 
| 28 | 101 |  |  |  |  |  | switch (len & 7) { | 
| 29 | 0 |  |  |  |  |  | case 7: h ^= uint64_t(data2[6]) << 48; // fallthrough | 
| 30 | 0 |  |  |  |  |  | case 6: h ^= uint64_t(data2[5]) << 40; // fallthrough | 
| 31 | 0 |  |  |  |  |  | case 5: h ^= uint64_t(data2[4]) << 32; // fallthrough | 
| 32 | 17 |  |  |  |  |  | case 4: h ^= uint64_t(data2[3]) << 24; // fallthrough | 
| 33 | 17 |  |  |  |  |  | case 3: h ^= uint64_t(data2[2]) << 16; // fallthrough | 
| 34 | 17 |  |  |  |  |  | case 2: h ^= uint64_t(data2[1]) << 8; // fallthrough | 
| 35 | 17 |  |  |  |  |  | case 1: h ^= uint64_t(data2[0]); | 
| 36 | 17 |  |  |  |  |  | h *= m; | 
| 37 |  |  |  |  |  |  | }; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 101 |  |  |  |  |  | h ^= h >> r; | 
| 40 | 101 |  |  |  |  |  | h *= m; | 
| 41 | 101 |  |  |  |  |  | h ^= h >> r; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 101 |  |  |  |  |  | return h; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  |  |  |  |  | uint32_t hash_jenkins_one_at_a_time (const char *key, size_t len) { | 
| 47 |  |  |  |  |  |  | uint32_t hash, i; | 
| 48 | 0 | 0 |  |  |  |  | for (hash = i = 0; i < len; ++i) { | 
| 49 | 0 |  |  |  |  |  | hash += key[i]; | 
| 50 | 0 |  |  |  |  |  | hash += (hash << 10); | 
| 51 | 0 |  |  |  |  |  | hash ^= (hash >> 6); | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 0 |  |  |  |  |  | hash += (hash << 3); | 
| 54 | 0 |  |  |  |  |  | hash ^= (hash >> 11); | 
| 55 | 0 |  |  |  |  |  | hash += (hash << 15); | 
| 56 | 0 |  |  |  |  |  | return hash; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 0 |  |  |  |  |  | char* crypt_xor (const char* source, size_t slen, const char* key, size_t klen, char* dest) { | 
| 60 |  |  |  |  |  |  | unsigned char* buf; | 
| 61 | 0 | 0 |  |  |  |  | if (dest) buf = (unsigned char*) dest; | 
| 62 |  |  |  |  |  |  | else { | 
| 63 | 0 |  |  |  |  |  | buf = (unsigned char*) malloc(slen+1); // space for '0' | 
| 64 | 0 | 0 |  |  |  |  | if (!buf) throw std::bad_alloc(); | 
| 65 |  |  |  |  |  |  | } | 
| 66 | 0 | 0 |  |  |  |  | for (size_t i = 0; i < slen; ++i) buf[i] = ((unsigned char) source[i]) ^ ((unsigned char) key[i % klen]); | 
| 67 | 0 |  |  |  |  |  | buf[slen] = 0; | 
| 68 | 0 |  |  |  |  |  | return (char*) buf; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | }} |