-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlqList.cpp
112 lines (93 loc) · 2.08 KB
/
AlqList.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "AlqList.h"
#include <functional>
#include <algorithm>
AlqList::AlqList() : AlqList(false)
{}
AlqList::AlqList(bool mGrouping) : mGrouping(mGrouping)
{}
void AlqList::moveFrom(AlqList &from)
{
std::move(from.mList.begin(), from.mList.end(), back_inserter(mList));
from.mList.clear();
}
bool AlqList::empty()
{
return mList.empty();
}
Event AlqList::popFront()
{
Event toReturn{std::move(mList.front())};
mList.pop_front();
return toReturn;
}
Event AlqList::popBack()
{
Event toReturn{std::move(mList.back())};
mList.pop_back();
return toReturn;
}
int AlqList::size()
{
return mList.size();
}
int AlqList::totalSize()
{
int toReturn = 0;
for (auto it = mList.begin(); it != mList.end(); ++it)
{
Event& e = *it;
toReturn += e.size();
}
return toReturn;
}
void AlqList::add(Event &&event)
{
mList.push_back(std::move(event));
}
void AlqList::addOrdered(Event &&event)
{
for (auto& it = mList.begin(); it != mList.end(); it++) {
Event &listEvent = *it;
if (event() < listEvent()) {
mList.insert(it, std::move(event));
break;
} else if (event() == listEvent()) {
if (mGrouping) {
listEvent.add(std::move(event));
} else {
mList.insert(it, std::move(event));
}
break;
}
}
mList.push_back(std::move(event));
}
Event &AlqList::front()
{
return mList.front();
}
Event &AlqList::back()
{
return mList.back();
}
void AlqList::addFront(Event &&event)
{
mList.push_front(std::move(event));
}
AlqList &AlqList::operator=(AlqList &&other) noexcept
{
mGrouping = other.mGrouping;
mList = std::move(other.mList);
return *this;
}
void AlqList::sort()
{
static std::function<bool(const Event&, const Event&)> predicate = [](const Event& left, const Event& right) {
return left() < right();
};
//std::sort(mList.begin(), mList.end(), predicate);
mList.sort(predicate);
// TODO @BK std::list is not sortable
// std::sort(mList.begin(), mList.end(),);
}
AlqList::~AlqList() = default;