sead
Loading...
Searching...
No Matches
seadListImpl.h
Go to the documentation of this file.
1#ifndef SEAD_LIST_IMPL_H_
2#define SEAD_LIST_IMPL_H_
3
4#include <random/seadRandom.h>
5
6namespace sead {
7
8class Random;
9
11{
12public:
14 : mPrev(nullptr)
15 , mNext(nullptr)
16 {
17 }
18
19private:
21 const ListNode& operator=(const ListNode&);
22
23public:
24 ListNode* next() const { return mNext; }
25 ListNode* prev() const { return mPrev; }
26
27 bool isLinked() const { return mNext || mPrev; }
28
29private:
30 void init_()
31 {
32 mNext = nullptr;
33 mPrev = nullptr;
34 }
35
36 void insertBack_(ListNode* n);
37 void insertFront_(ListNode* n);
38 void erase_();
39
40private:
43
44 friend class ListImpl;
45};
46#ifdef cafe
47static_assert(sizeof(ListNode) == 0x8, "sead::ListNode size mismatch");
48#endif // cafe
49
51{
52protected:
53 using CompareCallbackImpl = s32 (*)(const void* a, const void* b);
54
55public:
63
64protected:
66
67public:
68 bool isEmpty() const { return mCount == 0; }
69
70 s32 size() const { return mCount; }
71
72 void reverse();
73
74 void shuffle()
75 {
76 Random random;
77 shuffle(&random);
78 }
79
80 void shuffle(Random* random);
81 bool checkLinks() const;
82
83protected:
84 void sort(s32 offset, CompareCallbackImpl cmp);
85 void mergeSort(s32 offset, CompareCallbackImpl cmp);
86
88 {
90 mCount += 1;
91 }
92
94 {
96 mCount += 1;
97 }
98
101
103 {
104 basis->insertFront_(n);
105 mCount += 1;
106 }
107
109 {
110 basis->insertBack_(n);
111 mCount += 1;
112 }
113
115 {
116 n->erase_();
117 mCount -= 1;
118 }
119
120 ListNode* front() const { return mCount > 0 ? mStartEnd.mNext : nullptr; }
121 ListNode* back() const { return mCount > 0 ? mStartEnd.mPrev : nullptr; }
122
123 ListNode* nth(s32 index) const;
124 s32 indexOf(const ListNode* n) const;
125
126 void swap(ListNode* n1, ListNode* n2);
127 void moveAfter(ListNode* basis, ListNode* n);
128 void moveBefore(ListNode* basis, ListNode* n);
129
130 ListNode* find(const void* ptr, s32 offset, CompareCallbackImpl cmp) const;
131 void uniq(s32 offset, CompareCallbackImpl cmp);
132
133 void clear();
134
136 {
137 mCount = 0;
140 }
141
142 static void mergeSortImpl(ListNode* front, ListNode* back, s32 num, s32 offset, CompareCallbackImpl cmp);
144
145protected:
148};
149#ifdef cafe
150static_assert(sizeof(ListImpl) == 0xC, "sead::ListImpl size mismatch");
151#endif // cafe
152
153} // namespace sead
154
155#endif // SEAD_LIST_IMPL_H_
Definition seadListImpl.h:51
void moveBefore(ListNode *basis, ListNode *n)
void swap(ListNode *n1, ListNode *n2)
void pushFront(ListNode *n)
Definition seadListImpl.h:93
void clear()
Definition seadListImpl.cpp:79
s32 mCount
Definition seadListImpl.h:147
ListNode * popFront()
Definition seadListImpl.cpp:64
static void mergeSortImpl(ListNode *front, ListNode *back, s32 num, s32 offset, CompareCallbackImpl cmp)
Definition seadListImpl.cpp:93
bool isEmpty() const
Definition seadListImpl.h:68
ListNode * back() const
Definition seadListImpl.h:121
ListNode * nth(s32 index) const
void uniq(s32 offset, CompareCallbackImpl cmp)
ListImpl & operator=(const ListImpl &)
void insertAfter(ListNode *basis, ListNode *n)
Definition seadListImpl.h:108
s32 indexOf(const ListNode *n) const
ListNode * find(const void *ptr, s32 offset, CompareCallbackImpl cmp) const
ListNode * popBack()
Definition seadListImpl.cpp:49
void insertBefore(ListNode *basis, ListNode *n)
Definition seadListImpl.h:102
ListImpl()
Definition seadListImpl.h:56
void pushBack(ListNode *n)
Definition seadListImpl.h:87
void moveAfter(ListNode *basis, ListNode *n)
ListImpl(const ListImpl &)
ListNode mStartEnd
Definition seadListImpl.h:146
void shuffle()
Definition seadListImpl.h:74
void mergeSort(s32 offset, CompareCallbackImpl cmp)
void shuffle(Random *random)
void sort(s32 offset, CompareCallbackImpl cmp)
bool checkLinks() const
void unsafeClear()
Definition seadListImpl.h:135
s32 size() const
Definition seadListImpl.h:70
void erase(ListNode *n)
Definition seadListImpl.h:114
ListNode * front() const
Definition seadListImpl.h:120
Definition seadListImpl.h:11
ListNode * mPrev
Definition seadListImpl.h:41
const ListNode & operator=(const ListNode &)
void init_()
Definition seadListImpl.h:30
bool isLinked() const
Definition seadListImpl.h:27
ListNode * prev() const
Definition seadListImpl.h:25
void erase_()
Definition seadListImpl.cpp:35
ListNode(const ListNode &)
ListNode * next() const
Definition seadListImpl.h:24
void insertFront_(ListNode *n)
Definition seadListImpl.cpp:21
ListNode * mNext
Definition seadListImpl.h:42
void insertBack_(ListNode *n)
Definition seadListImpl.cpp:7
ListNode()
Definition seadListImpl.h:13
Definition seadRandom.h:9
Definition seadAssert.h:44