Some documentation

This commit is contained in:
TinyAtoms
2020-02-18 00:00:25 -03:00
parent b82199e3b0
commit 94b7399926
39 changed files with 87 additions and 8900 deletions

View File

@@ -18,14 +18,34 @@ using namespace std::chrono;
using std::vector;
using std::cout;
/*
This is yet again a template function.
basic functionality is like this:
1. we create a vector to store the times
2. we create and populate vectors for keys that will be used for the tests
3. create the hashmap.
4. call prepare(hashmap, size)
5. populate the hashmap with size - 10 k,v pairs
6. benchmark the vector access time, which will be subtracted later
7. insert 10k keys(from insert_keys) and time it
8. lookup 10k keys(from sample_keys) and time it
9. lookup 10k nonexistent keys(nonkeys) and time it
10. delete 10k keys(sample_keys) and time it
times are added to the results vector, and that is returned.
(4) this step is called because some hashmaps require some extra steps before
you use them. For example, setting a key that will be the thombstone marker, the
key that will mark a location as empty, etc.
*/
template<class T>
vector<int> int_test(T map, int size) {
vector<int> results; // insert, lookup, unsuccesful lookup, delete times
vector<int> sample_keys; // get a sample of keys to lookup and later delete
vector<int> sample_keys; // get a sample of keys to lookup and later delete, will be filled later
// unsuccesful lookup keys
vector<int> nonkeys(10000);
// generate uses a function(here, gen_unsuccesfull_int) to fill a container with values
std::generate(nonkeys.begin(), nonkeys.end(), gen_unsuccesfull_int);
// keys for insert test
@@ -38,12 +58,17 @@ vector<int> int_test(T map, int size) {
{ // seperate scope, so all_keys gets destroyed. for good measure, empty it too
vector<int> all_keys(size - 10000);
std::generate(all_keys.begin(), all_keys.end(), gen_int);
// sample inserts x ammount of values from old_container to
// new_container with the help of a generator instance
// in this case, random 10k keys from all_keys to sample_keys
std::sample(all_keys.begin(), all_keys.end(), std::back_inserter(sample_keys), 10000, generator);
for (auto i : all_keys) {
testmap.insert({i, i});
}
all_keys.clear();
all_keys.clear(); // going out of scope should call the destructor to
// clear it, but just making sure it's done
}
@@ -65,7 +90,7 @@ vector<int> int_test(T map, int size) {
auto insert_time = (duration_cast<nanoseconds>(insert_end - insert_start) - vector_acces_time) / 10000;
results.push_back(insert_time.count());
// remove some memory
// clear all values in here, clear up some memory
insert_keys.clear();
// lookup test
@@ -103,7 +128,9 @@ vector<int> int_test(T map, int size) {
}
// pretty much the same, but with strings
// the reason it's split up in 2 functions is because we need other functions to
// generate the keys, and unfortunately we can't overload based on return type
template<class T>
vector<int> string_test(T map, int size) {
vector<int> results; // insert, lookup, unsuccesful lookup, delete times