Platform.Data.Doublets C++
Loading...
Searching...
No Matches
ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h
Go to the documentation of this file.
2{
3 template <typename TSelf, typename TLinksOptions>
5 : public Platform::Collections::Methods::Trees::RecursionlessSizeBalancedTreeMethods<
6 TSelf,
7 typename TLinksOptions::LinkAddressType> /*, ILinksTreeMethods<typename TLinksOptions::LinkAddressType>*/
8 {
9 public:
10 using LinksOptionsType = TLinksOptions;
11
12 public:
13 static constexpr auto Constants = LinksOptionsType::Constants;
14
15 public:
16 using LinkAddressType = typename LinksOptionsType::LinkAddressType;
17 using LinkType = typename LinksOptionsType::LinkType;
18 using WriteHandlerType = typename LinksOptionsType::WriteHandlerType;
19 using ReadHandlerType = typename LinksOptionsType::ReadHandlerType;
20
21 public:
23
24 public:
25 static constexpr LinkAddressType Continue = Constants.Continue;
26
27 public:
28 std::byte* LinksDataParts;
29
30 public:
31 std::byte* LinksIndexParts;
32
33 public:
34 std::byte* Header;
35
36 public:
37 ExternalLinksRecursionlessSizeBalancedTreeMethodsBase(std::byte* linksDataParts, std::byte* linksIndexParts,
38 std::byte* header)
39 {
40 LinksDataParts = linksDataParts;
41 LinksIndexParts = linksIndexParts;
42 Header = header;
43 }
44
45 public:
47 {
48 return this->object().GetTreeRoot();
49 };
50
51 public:
53 {
54 return this->object().GetBasePartValue(link);
55 };
56
57 public:
59 LinkAddressType rootTarget)
60 {
61 return this->object().FirstIsToTheRightOfSecond(source, target, rootSource, rootTarget);
62 };
63
64 public:
66 LinkAddressType rootTarget)
67 {
68 return this->object().FirstIsToTheLeftOfSecond(source, target, rootSource, rootTarget);
69 };
70
71 public:
73 {
74 return *reinterpret_cast<LinksHeader<LinkAddressType>*>(Header);
75 }
76
77 public:
83
84 public:
90
91 public:
93 {
94 auto& link = GetLinkDataPartReference(linkIndex);
95 return LinkType{linkIndex, link.Source, link.Target};
96 }
97
98 public:
100 {
101 auto& firstLink = this->GetLinkDataPartReference(first);
102 auto& secondLink = this->GetLinkDataPartReference(second);
103 return this->FirstIsToTheLeftOfSecond(firstLink.Source, firstLink.Target, secondLink.Source,
104 secondLink.Target);
105 }
106
107 public:
109 {
110 auto& firstLink = this->GetLinkDataPartReference(first);
111 auto& secondLink = this->GetLinkDataPartReference(second);
112 return this->FirstIsToTheRightOfSecond(firstLink.Source, firstLink.Target, secondLink.Source,
113 secondLink.Target);
114 }
115
116 public:
118 {
119 auto root = GetTreeRoot();
120 if (index >= this->object().GetSize(root))
121 {
122 return 0;
123 }
124 while (root != 0)
125 {
126 auto left = GetLeftOrDefault(root);
127 auto leftSize = GetSizeOrZero(left);
128 if (index < leftSize)
129 {
130 root = left;
131 continue;
132 }
133 if (AreEqual(index, leftSize))
134 {
135 return root;
136 }
137 root = GetRightOrDefault(root);
138 index = index - (leftSize + 1);
139 }
140 return 0;
141 }
142
143 public:
145 {
146 auto root = this->GetTreeRoot();
147 while (root != 0)
148 {
149 auto& rootLink = this->GetLinkDataPartReference(root);
150 auto rootSource = rootLink.Source;
151 auto rootTarget = rootLink.Target;
152 if (this->FirstIsToTheLeftOfSecond(source, target, rootSource, rootTarget))
153 {
154 root = this->GetLeftOrDefault(root);
155 }
156 else if (this->FirstIsToTheRightOfSecond(source, target, rootSource, rootTarget))
157 {
158 root = this->GetRightOrDefault(root);
159 }
160 else
161 {
162 return root;
163 }
164 }
165 return 0;
166 }
167
168 public:
170 {
171 auto root = this->GetTreeRoot();
172 auto total = this->object().GetSize(root);
173 auto totalRightIgnore = 0;
174 while (root != 0)
175 {
176 auto base = this->GetBasePartValue(root);
177 if (base <= link)
178 {
179 root = this->GetRightOrDefault(root);
180 }
181 else
182 {
183 totalRightIgnore = totalRightIgnore + (this->GetRightSize(root) + 1);
184 root = this->GetLeftOrDefault(root);
185 }
186 }
187 root = this->GetTreeRoot();
188 auto totalLeftIgnore = 0;
189 while (root != 0)
190 {
191 auto base = this->GetBasePartValue(root);
192 if (base >= link)
193 {
194 root = this->GetLeftOrDefault(root);
195 }
196 else
197 {
198 totalLeftIgnore = totalLeftIgnore + (this->GetLeftSize(root) + 1);
199 root = this->GetRightOrDefault(root);
200 }
201 }
202 return (total - totalRightIgnore) - totalLeftIgnore;
203 }
204
205 public:
207 {
208 return this->EachUsageCore(base, this->GetTreeRoot(), handler);
209 }
210
211 private:
212 LinkAddressType EachUsageCore(LinkAddressType base, LinkAddressType link, const ReadHandlerType& handler)
213 {
214 if (link == 0)
215 {
216 return Continue;
217 }
218 auto linkBasePart = this->GetBasePartValue(link);
219 if (linkBasePart > (base))
220 {
221 if ((this->EachUsageCore(base, this->GetLeftOrDefault(link), handler) == Break))
222 {
223 return Break;
224 }
225 }
226 else if (linkBasePart < base)
227 {
228 if ((this->EachUsageCore(base, this->GetRightOrDefault(link), handler) == Break))
229 {
230 return Break;
231 }
232 }
233 else
234 {
235 if (handler(this->GetLinkValues(link)) == Break)
236 {
237 return Break;
238 }
239 if ((this->EachUsageCore(base, this->GetLeftOrDefault(link), handler) == Break))
240 {
241 return Break;
242 }
243 if ((this->EachUsageCore(base, this->GetRightOrDefault(link), handler) == Break))
244 {
245 return Break;
246 }
247 }
248 return Continue;
249 }
250 };
251} // namespace Platform::Data::Doublets::Memory::Split::Generic
LinkAddressType Search(LinkAddressType source, LinkAddressType target)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:144
static constexpr LinkAddressType Break
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:22
LinkAddressType CountUsages(LinkAddressType link)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:169
static constexpr auto Constants
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:13
static constexpr LinkAddressType Continue
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:25
RawLinkDataPart< LinkAddressType > & GetLinkDataPartReference(LinkAddressType link)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:78
bool FirstIsToTheLeftOfSecond(LinkAddressType source, LinkAddressType target, LinkAddressType rootSource, LinkAddressType rootTarget)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:65
auto & GetHeaderReference()
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:72
LinkAddressType GetTreeRoot()
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:46
typename LinksOptionsType::LinkType LinkType
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:17
auto GetLinkValues(LinkAddressType linkIndex)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:92
LinkAddressType GetBasePartValue(LinkAddressType link)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:52
RawLinkIndexPart< LinkAddressType > & GetLinkIndexPartReference(LinkAddressType link)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:85
LinkAddressType operator[](LinkAddressType index)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:117
bool FirstIsToTheRightOfSecond(LinkAddressType source, LinkAddressType target, LinkAddressType rootSource, LinkAddressType rootTarget)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:58
bool FirstIsToTheRightOfSecond(LinkAddressType first, LinkAddressType second)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:108
std::byte * LinksIndexParts
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:31
TLinksOptions LinksOptionsType
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:10
LinkAddressType EachUsage(LinkAddressType base, const ReadHandlerType &handler)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:206
typename LinksOptionsType::LinkAddressType LinkAddressType
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:16
std::byte * LinksDataParts
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:28
ExternalLinksRecursionlessSizeBalancedTreeMethodsBase(std::byte *linksDataParts, std::byte *linksIndexParts, std::byte *header)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:37
std::byte * Header
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:34
typename LinksOptionsType::ReadHandlerType ReadHandlerType
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:19
typename LinksOptionsType::WriteHandlerType WriteHandlerType
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:18
bool FirstIsToTheLeftOfSecond(LinkAddressType first, LinkAddressType second)
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:99
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:2