X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FSpookyHashV2.h;h=9cc3474a68a0f7d42a18d528371831ac419406f6;hp=b5121addc534be6cda3f7ed8bf8cb999f17ec115;hb=5cef863eee8a03e1b6b137fb283d6fe703f35d2d;hpb=5c77fedbef46995a71ffa268c9fcaf49efddd01b diff --git a/folly/SpookyHashV2.h b/folly/SpookyHashV2.h index b5121add..9cc3474a 100644 --- a/folly/SpookyHashV2.h +++ b/folly/SpookyHashV2.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,7 @@ // slower than MD5. // -#ifndef FOLLY_SPOOKYHASHV2_H_ -#define FOLLY_SPOOKYHASHV2_H_ +#pragma once #include #include @@ -114,8 +113,8 @@ public: // all the pieces concatenated into one message. // void Final( - uint64_t *hash1, // out only: first 64 bits of hash value. - uint64_t *hash2); // out only: second 64 bits of hash value. + uint64_t *hash1, // out only: first 64 bits of hash value. + uint64_t *hash2) const; // out only: second 64 bits of hash value. // // left rotate a 64-bit value by k bytes @@ -144,18 +143,18 @@ public: uint64_t &s4, uint64_t &s5, uint64_t &s6, uint64_t &s7, uint64_t &s8, uint64_t &s9, uint64_t &s10,uint64_t &s11) { - s0 += data[0]; s2 ^= s10; s11 ^= s0; s0 = Rot64(s0,11); s11 += s1; - s1 += data[1]; s3 ^= s11; s0 ^= s1; s1 = Rot64(s1,32); s0 += s2; - s2 += data[2]; s4 ^= s0; s1 ^= s2; s2 = Rot64(s2,43); s1 += s3; - s3 += data[3]; s5 ^= s1; s2 ^= s3; s3 = Rot64(s3,31); s2 += s4; - s4 += data[4]; s6 ^= s2; s3 ^= s4; s4 = Rot64(s4,17); s3 += s5; - s5 += data[5]; s7 ^= s3; s4 ^= s5; s5 = Rot64(s5,28); s4 += s6; - s6 += data[6]; s8 ^= s4; s5 ^= s6; s6 = Rot64(s6,39); s5 += s7; - s7 += data[7]; s9 ^= s5; s6 ^= s7; s7 = Rot64(s7,57); s6 += s8; - s8 += data[8]; s10 ^= s6; s7 ^= s8; s8 = Rot64(s8,55); s7 += s9; - s9 += data[9]; s11 ^= s7; s8 ^= s9; s9 = Rot64(s9,54); s8 += s10; - s10 += data[10]; s0 ^= s8; s9 ^= s10; s10 = Rot64(s10,22); s9 += s11; - s11 += data[11]; s1 ^= s9; s10 ^= s11; s11 = Rot64(s11,46); s10 += s0; + s0 += data[0]; s2 ^= s10; s11 ^= s0; s0 = Rot64(s0,11); s11 += s1; + s1 += data[1]; s3 ^= s11; s0 ^= s1; s1 = Rot64(s1,32); s0 += s2; + s2 += data[2]; s4 ^= s0; s1 ^= s2; s2 = Rot64(s2,43); s1 += s3; + s3 += data[3]; s5 ^= s1; s2 ^= s3; s3 = Rot64(s3,31); s2 += s4; + s4 += data[4]; s6 ^= s2; s3 ^= s4; s4 = Rot64(s4,17); s3 += s5; + s5 += data[5]; s7 ^= s3; s4 ^= s5; s5 = Rot64(s5,28); s4 += s6; + s6 += data[6]; s8 ^= s4; s5 ^= s6; s6 = Rot64(s6,39); s5 += s7; + s7 += data[7]; s9 ^= s5; s6 ^= s7; s7 = Rot64(s7,57); s6 += s8; + s8 += data[8]; s10 ^= s6; s7 ^= s8; s8 = Rot64(s8,55); s7 += s9; + s9 += data[9]; s11 ^= s7; s8 ^= s9; s9 = Rot64(s9,54); s8 += s10; + s10 += data[10]; s0 ^= s8; s9 ^= s10; s10 = Rot64(s10,22); s9 += s11; + s11 += data[11]; s1 ^= s9; s10 ^= s11; s11 = Rot64(s11,46); s10 += s0; } // @@ -222,7 +221,8 @@ public: // with diffs defined by either xor or subtraction // with a base of all zeros plus a counter, or plus another bit, or random // - static inline void ShortMix(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3) + static inline void ShortMix(uint64_t &h0, uint64_t &h1, + uint64_t &h2, uint64_t &h3) { h2 = Rot64(h2,50); h2 += h3; h0 ^= h2; h3 = Rot64(h3,52); h3 += h0; h1 ^= h3; @@ -250,7 +250,8 @@ public: // For every pair of input bits, // with probability 50 +- .75% (the worst case is approximately that) // - static inline void ShortEnd(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3) + static inline void ShortEnd(uint64_t &h0, uint64_t &h1, + uint64_t &h2, uint64_t &h3) { h3 ^= h2; h2 = Rot64(h2,15); h3 += h2; h0 ^= h3; h3 = Rot64(h3,52); h0 += h3; @@ -274,19 +275,19 @@ private: // held to the same quality bar. // static void Short( - const void *message, // message (array of bytes, not necessarily aligned) + const void *message, // message (byte array, not necessarily aligned) size_t length, // length of message (in bytes) uint64_t *hash1, // in/out: in the seed, out the hash value uint64_t *hash2); // in/out: in the seed, out the hash value // number of uint64_t's in internal state - static const size_t sc_numVars = 12; + static constexpr size_t sc_numVars = 12; // size of the internal state - static const size_t sc_blockSize = sc_numVars*8; + static constexpr size_t sc_blockSize = sc_numVars*8; // size of buffer of unhashed data, in bytes - static const size_t sc_bufSize = 2*sc_blockSize; + static constexpr size_t sc_bufSize = 2*sc_blockSize; // // sc_const: a constant which: @@ -295,7 +296,7 @@ private: // * is a not-very-regular mix of 1's and 0's // * does not need any other special mathematical properties // - static const uint64_t sc_const = 0xdeadbeefdeadbeefLL; + static constexpr uint64_t sc_const = 0xdeadbeefdeadbeefULL; uint64_t m_data[2*sc_numVars]; // unhashed data, for partial messages uint64_t m_state[sc_numVars]; // internal state of the hash @@ -305,5 +306,3 @@ private: } // namespace hash } // namespace folly - -#endif