-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
79 lines (65 loc) · 2.06 KB
/
main.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
77
78
79
#include <cassert>
#include <cstdint>
#include <iostream>
#include "PersistentSet/PatriciaSet.h"
#include "Allocators/TwoPoolsAllocator.h"
#include "Allocators/HeapAllocator.h"
#include "Allocators/FreeListAllocator.h"
template <patricia::Unsigned T, patricia::BitmapC Bitmap, typename Alloc = std::allocator<patricia::detail::IntPatriciaNode<T, Bitmap>>>
void SimpleTest() {
// simple persistent set example
patricia::IntSet<T, Bitmap, Alloc> set;
// set = {0, 1, ..., 41}
for (std::uint32_t i = 0; i < 42; ++i) {
set.insert(i);
assert(set.contains(i));
}
// set2 = {0, 1, ..., 41}
auto set2 = set;
// set = {0, ..., 40, 41, 42}
// set2 = {0, ..., 40, 41, 43}
set.insert(42);
set2.insert(43);
for (std::uint32_t i = 0; i < 44; ++i) {
if (i < 42) {
assert(set.contains(i));
assert(set2.contains(i));
}
else if (i == 42) {
assert(set.contains(i));
assert(!set2.contains(i));
}
else if (i == 43) {
assert(!set.contains(i));
assert(set2.contains(i));
}
}
// set = {}
// set2 = {0, ..., 40, 41, 43}
set.clear();
for (std::uint32_t i = 0; i < 42; ++i) {
assert(!set.contains(i));
assert(set2.contains(i));
}
}
template <typename Alloc>
void SimpleAllocatorTest() {
patricia::IntSet<std::uint64_t, std::uint64_t, Alloc> set;
set.insert(1);
assert(set.contains(1));
set.clear();
assert(!set.contains(1));
}
int main()
{
SimpleTest<std::uint32_t, std::uint32_t>();
SimpleTest<std::uint32_t, std::uint64_t>();
SimpleTest<std::uint32_t, patricia::NoBitmap>();
SimpleTest<std::uint32_t, patricia::NoBitmap, StdTwoPoolsAllocator<void, 1 << 10, 72, 40>>();
SimpleAllocatorTest<StdTwoPoolsAllocator<void, 1 << 10, 72, 48>>();
SimpleAllocatorTest<StdFreeListAllocator<void, 72>>();
SimpleAllocatorTest<StdHeapAllocator<void>>();
SimpleAllocatorTest<std::allocator<void>>();
std::cout << "All tests passed\n";
return 0;
}