37 const int N = 20 * 1000 * 1000;
40 char** commands =
new char*[N];
41 pair<uint64_t, int>* hashes =
new pair<uint64_t, int>[N];
43 srand((
int)time(NULL));
45 for (
int i = 0; i < N; ++i) {
50 sort(hashes, hashes + N);
52 int collision_count = 0;
53 for (
int i = 1; i < N; ++i) {
54 if (hashes[i - 1].first == hashes[i].first) {
55 if (strcmp(commands[hashes[i - 1].second],
56 commands[hashes[i].second]) != 0) {
57 printf(
"collision!\n string 1: '%s'\n string 2: '%s'\n",
58 commands[hashes[i - 1].second],
59 commands[hashes[i].second]);
64 printf(
"\n\n%d collisions after %d runs\n", collision_count, N);
static uint64_t HashCommand(StringPiece command)