* limitations under the License.
*/
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include <cstdio>
+#include <cinttypes>
#include <string>
"const uint64_t FingerprintTable<%d>::poly[%d] = {",
DEG+1, FingerprintPolynomial<DEG>::size()));
for (int j = 0; j < FingerprintPolynomial<DEG>::size(); j++) {
- CHECK_ERR(fprintf(file, "%s%luLU", j ? ", " : "", poly_val[j]));
+ CHECK_ERR(fprintf(file, "%s%" PRIu64 "LU", j ? ", " : "", poly_val[j]));
}
CHECK_ERR(fprintf(file, "};\n\n"));
for (int x = 0; x < 256; x++) {
CHECK_ERR(fprintf(file, " {"));
for (int j = 0; j < FingerprintPolynomial<DEG>::size(); j++) {
- CHECK_ERR(fprintf(file, "%s%luLU", (j ? ", " : ""), table[i][x][j]));
+ CHECK_ERR(fprintf(
+ file, "%s%" PRIu64 "LU", (j ? ", " : ""), table[i][x][j]));
}
CHECK_ERR(fprintf(file, "},\n"));
}
*/
// SpookyHash: a 128-bit noncryptographic hash function
// By Bob Jenkins, public domain
+
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include "folly/SpookyHashV1.h"
+#include "folly/Benchmark.h"
+#include <cinttypes>
#include <cstdio>
#include <cstddef>
#include <cstring>
SpookyHashV1::Hash128(buf[i], BUFSIZE, &hash1, &hash2);
}
uint64_t z = GetTickCount();
- printf("SpookyHashV1::Hash128, uncached: time is %4lu milliseconds\n", z-a);
+ printf("SpookyHashV1::Hash128, uncached: time is "
+ "%4" PRIu64 " milliseconds\n", z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF; ++i)
Add(buf[i], BUFSIZE, &hash1, &hash2);
}
z = GetTickCount();
- printf("Addition , uncached: time is %4lu milliseconds\n", z-a);
+ printf("Addition , uncached: time is "
+ "%4" PRIu64 " milliseconds\n", z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF*BUFSIZE/1024; ++i)
SpookyHashV1::Hash128(buf[0], 1024, &hash1, &hash2);
}
z = GetTickCount();
- printf("SpookyHashV1::Hash128, cached: time is %4lu milliseconds\n", z-a);
+ printf("SpookyHashV1::Hash128, cached: time is "
+ "%4" PRIu64 " milliseconds\n", z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF*BUFSIZE/1024; ++i)
Add(buf[0], 1024, &hash1, &hash2);
}
z = GetTickCount();
- printf("Addition , cached: time is %4lu milliseconds\n", z-a);
+ printf("Addition , cached: time is "
+ "%4" PRIu64 " milliseconds\n", z-a);
for (int i=0; i<NUMBUF; ++i)
{
#define NUMITER 10000000
void DoTimingSmall(int seed)
{
- printf("\ntesting timing of hashing up to %d cached aligned bytes %d times ...\n",
- BUFSIZE, NUMITER);
+ printf("\ntesting timing of hashing up to %d cached aligned bytes %d "
+ "times ...\n", BUFSIZE, NUMITER);
uint64_t buf[BUFSIZE/8];
for (int i=0; i<BUFSIZE/8; ++i)
SpookyHashV1::Hash128((char *)buf, i, &hash1, &hash2);
}
uint64_t z = GetTickCount();
- printf("%d bytes: hash is %.16lx %.16lx, time is %lu\n",
- i, hash1, hash2, z-a);
+ printf("%d bytes: hash is %.16" PRIx64 " %.16" PRIx64 ", "
+ "time is %" PRIu64 "\n", i, hash1, hash2, z-a);
}
}
#undef BUFSIZE
#define MEASURES 6
void TestDeltas(int seed)
{
- printf("\nall 1 or 2 bit input deltas get %d tries to flip every output bit ...\n", TRIES);
+ printf("\nall 1 or 2 bit input deltas get %d tries to flip every output "
+ "bit ...\n", TRIES);
Random random;
random.Init((uint64_t)seed);
if (a != c)
{
- printf("wrong a %d: %.16lx %.16lx\n", i, a,c);
+ printf("wrong a %d: %.16" PRIx64 " %.16" PRIx64 "\n", i, a,c);
failed = true;
}
if (b != d)
{
- printf("wrong b %d: %.16lx %.16lx\n", i, b,d);
+ printf("wrong b %d: %.16" PRIx64 " %.16" PRIx64 "\n", i, b,d);
failed = true;
}
state.Final(&c, &d);
if (a != c)
{
- printf("wrong a %d %d: %.16lx %.16lx\n", j, i, a,c);
+ printf("wrong a %d %d: %.16" PRIx64 " %.16" PRIx64 "\n",
+ j, i, a,c);
failed = true;
}
if (b != d)
{
- printf("wrong b %d %d: %.16lx %.16lx\n", j, i, b,d);
+ printf("wrong b %d %d: %.16" PRIx64 " %.16" PRIx64 "\n",
+ j, i, b,d);
failed = true;
}
}
*/
// SpookyHash: a 128-bit noncryptographic hash function
// By Bob Jenkins, public domain
+
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include "folly/SpookyHashV2.h"
+#include "folly/Benchmark.h"
+#include <cinttypes>
#include <cstdio>
#include <cstddef>
#include <cstring>
saw[i] = SpookyHashV2::Hash32(buf, i, 0);
if (saw[i] != expected[i])
{
- printf("%3d: saw 0x%.8x, expected 0x%.8lx\n", i, saw[i], expected[i]);
+ printf("%3d: saw 0x%.8x, expected 0x%.8" PRIx64 "\n", i, saw[i],
+ expected[i]);
failed = true;
}
}
uint64_t hash2 = seed;
for (uint64_t i=0; i<NUMBUF; ++i)
{
- SpookyHashV2::Hash128(buf[i], BUFSIZE, &hash1, &hash2);
+ SpookyHashV2::Hash128(buf[i], BUFSIZE, &hash1, &hash2);
}
uint64_t z = GetTickCount();
- printf("SpookyHashV2::Hash128, uncached: time is %4ld milliseconds\n", z-a);
+ printf("SpookyHashV2::Hash128, uncached: time is "
+ "%4" PRId64 " milliseconds\n", z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF; ++i)
{
- Add(buf[i], BUFSIZE, &hash1, &hash2);
+ Add(buf[i], BUFSIZE, &hash1, &hash2);
}
z = GetTickCount();
- printf("Addition , uncached: time is %4ld milliseconds\n", z-a);
+ printf("Addition , uncached: time is %4" PRId64 " milliseconds\n",
+ z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF*BUFSIZE/1024; ++i)
{
- SpookyHashV2::Hash128(buf[0], 1024, &hash1, &hash2);
+ SpookyHashV2::Hash128(buf[0], 1024, &hash1, &hash2);
}
z = GetTickCount();
- printf("SpookyHashV2::Hash128, cached: time is %4ld milliseconds\n", z-a);
+ printf("SpookyHashV2::Hash128, cached: time is "
+ "%4" PRId64 " milliseconds\n", z-a);
a = GetTickCount();
for (uint64_t i=0; i<NUMBUF*BUFSIZE/1024; ++i)
{
- Add(buf[0], 1024, &hash1, &hash2);
+ Add(buf[0], 1024, &hash1, &hash2);
}
z = GetTickCount();
- printf("Addition , cached: time is %4ld milliseconds\n", z-a);
+ printf("Addition , cached: time is %4" PRId64 " milliseconds\n",
+ z-a);
for (int i=0; i<NUMBUF; ++i)
{
#define NUMITER 10000000
void DoTimingSmall(int seed)
{
- printf("\ntesting timing of hashing up to %d cached aligned bytes %d times ...\n",
- BUFSIZE, NUMITER);
+ printf("\ntesting timing of hashing up to %d cached aligned bytes %d "
+ "times ...\n", BUFSIZE, NUMITER);
uint64_t buf[BUFSIZE/8];
for (int i=0; i<BUFSIZE/8; ++i)
SpookyHashV2::Hash128((char *)buf, i, &hash1, &hash2);
}
uint64_t z = GetTickCount();
- printf("%d bytes: hash is %.16lx %.16lx, time is %ld\n",
- i, hash1, hash2, z-a);
+ printf("%d bytes: hash is %.16" PRIx64 " %.16" PRIx64 ", "
+ "time is %" PRId64 "\n", i, hash1, hash2, z-a);
}
}
#undef BUFSIZE
#define MEASURES 6
void TestDeltas(int seed)
{
- printf("\nall 1 or 2 bit input deltas get %d tries to flip every output bit ...\n", TRIES);
+ printf("\nall 1 or 2 bit input deltas get %d tries to flip every output "
+ "bit ...\n", TRIES);
Random random;
random.Init((uint64_t)seed);
SpookyHashV2::Hash128(buf, i, &a, &b);
// all as one piece
- c = 0xdeadbeefdeadbeef;
- d = 0xbaceba11baceba11;
+ c = 0xdeadbeefdeadbeef;
+ d = 0xbaceba11baceba11;
state.Init(seed1, seed2);
state.Update(buf, i);
state.Final(&c, &d);
if (a != c)
{
- printf("wrong a %d: %.16lx %.16lx\n", i, a,c);
+ printf("wrong a %d: %.16" PRIx64 " %.16" PRIx64 "\n", i, a,c);
failed = true;
}
if (b != d)
{
- printf("wrong b %d: %.16lx %.16lx\n", i, b,d);
+ printf("wrong b %d: %.16" PRIx64 " %.16" PRIx64 "\n", i, b,d);
failed = true;
}
state.Final(&c, &d);
if (a != c)
{
- printf("wrong a %d %d: %.16lx %.16lx\n", j, i, a,c);
+ printf("wrong a %d %d: %.16" PRIx64 " %.16" PRIx64 "\n",
+ j, i, a,c);
failed = true;
}
if (b != d)
{
- printf("wrong b %d %d: %.16lx %.16lx\n", j, i, b,d);
+ printf("wrong b %d %d: %.16" PRIx64 " %.16" PRIx64 "\n",
+ j, i, b,d);
failed = true;
}
}