-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
77 lines (57 loc) · 1.93 KB
/
Test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Includes...
// System...
#include <cassert>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <utility>
#include <vector>
// Our headers...
#include "SkipList.h"
// Use the standard namespace...
using namespace std;
// Entry point...
int main()
{
// Create a skip list that maps integers to strings...
SkipList<int, string> List;
// map<int, string> List;
// Initialize random generator...
// Random device to feed the generator...
std::random_device RandomDevice;
// Mersenne Twister random generator from the random device...
std::mt19937 RandomGenerator;
// Maximum integer to insert...
const int MaximumInteger = 100000;
// Generate a random pool of unique integers...
// Allocate enough storage for all integers...
vector<int> RandomIntegers(MaximumInteger);
// Fill with sequentially ordered integers...
iota(begin(RandomIntegers), end(RandomIntegers), 1);
// Randomly shuffle the integers...
shuffle(begin(RandomIntegers), end(RandomIntegers), RandomGenerator);
// Insert each integer key into the list with its string representation as
// the value...
for_each(cbegin(RandomIntegers), cend(RandomIntegers), [&List](const int &Key)
{
if(Key % 10000 == 0)
cout << "." << flush;
// cout << Key << endl;
//List.insert(make_pair(Key, to_string(Key)));
List.Insert(Key, to_string(Key));
});
// Check size...
assert(List.GetSize() == MaximumInteger);
cout << "Searching for 5..." << endl;
const auto Iterator = List.Search(5);
if(Iterator != cend(List))
cout << "Found: " << Iterator->second << endl;
else
cout << "Not found!" << endl;
cout << "Clearing..." << endl;
List.Clear();
// Check size...
assert(List.GetSize() == 0);
return 0;
}