Last active
December 12, 2015 01:48
-
-
Save angusb/4693554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <map> | |
#include <bitset> | |
#include <vector> | |
#include <cstdlib> | |
#include <inttypes.h> | |
#include <stdio.h> | |
#include <time.h> | |
using namespace std; | |
const int NUM_ELTS = 10000000; | |
void generate_random_nums(vector<int64_t>& ints) { | |
for (int i=0; i<NUM_ELTS; i++) { | |
int rand_int = rand(); | |
int64_t rand_num = static_cast<int64_t>(rand_int); | |
rand_num = (rand_num << 32) + rand(); | |
ints.push_back(rand_num); | |
} | |
} | |
int map_approach(vector<int64_t>& ints) { | |
map<int64_t, int> counts; | |
int num_dups = 0; | |
for (int i=0; i<NUM_ELTS; i++) { | |
counts[ints[i]] += 1; | |
if (counts[ints[i]] > 1) | |
num_dups++; | |
} | |
return num_dups; | |
} | |
int bitset_approach(vector<int64_t>& ints) { | |
int32_t top = 0xFFFFFFFF; | |
//cout << top << endl; | |
// bitset<4294967296> lower_32; // 4294967296 | |
// for (int i=0; i<NUM_ELTS; i++) { | |
// } | |
} | |
int sort_iterate_approach(vector<int64_t>& ints) { | |
sort(ints.begin(), ints.end()); | |
} | |
int main() { | |
vector<int64_t> ints; | |
time_t start, end; | |
generate_random_nums(ints); | |
time(&start); | |
int dups = sort_iterate_approach(ints); | |
time(&end); | |
cout << "Number of duplicates: " << dups << endl; | |
printf("Time taken: %.2f\n", difftime(end, start)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment