Platform.Data.Doublets C++
Loading...
Searching...
No Matches
ExternalLinksSizeBalancedTreeMethodsBase.h
Go to the documentation of this file.
2{
3 template <typename TSelf, typename TLinksOptions>
5 : public Platform::Collections::Methods::Trees::SizeBalancedTreeMethods<
6 TSelf, typename TLinksOptions::LinkAddressType> /* public ILinksTreeMethods<TLinksOptions>, */
7 {
8 public:
9 using Polymorph<TSelf>::object;
10 using LinksOptionsType = TLinksOptions;
11 static constexpr auto Constants = LinksOptionsType::Constants;
12 using LinkAddressType = typename LinksOptionsType::LinkAddressType;
13 using LinkType = typename LinksOptionsType::LinkType;
14 using WriteHandlerType = typename LinksOptionsType::WriteHandlerType;
15 using ReadHandlerType = typename LinksOptionsType::ReadHandlerType;
17 static constexpr LinkAddressType Continue = Constants.Continue;
18 std::byte* LinksDataParts;
19 std::byte* LinksIndexParts;
20 std::byte* Header;
21
22 public:
23 ExternalLinksSizeBalancedTreeMethodsBase(std::byte* linksDataParts, std::byte* linksIndexParts,
24 std::byte* header)
25 {
26 LinksDataParts = linksDataParts;
27 LinksIndexParts = linksIndexParts;
28 Header = header;
29 }
30
31 public:
33 {
34 return this->object().GetTreeRoot();
35 };
36
37 public:
39 {
40 return this->object().GetBasePartValue(link);
41 };
42
43 public:
45 LinkAddressType rootTarget)
46 {
47 return this->object().FirstIsToTheRightOfSecond(source, target, rootSource, rootTarget);
48 };
49
50 public:
52 LinkAddressType rootTarget)
53 {
54 return this->object().FirstIsToTheLeftOfSecond(source, target, rootSource, rootTarget);
55 };
56
57 public:
58 auto&& GetHeaderReference() const
59 {
60 return *reinterpret_cast<LinksHeader<LinkAddressType>*>(Header);
61 }
62
63 public:
69
70 public:
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 ((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
typename LinksOptionsType::LinkAddressType LinkAddressType
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:12
bool FirstIsToTheLeftOfSecond(LinkAddressType source, LinkAddressType target, LinkAddressType rootSource, LinkAddressType rootTarget)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:51
const RawLinkDataPart< LinkAddressType > & GetLinkDataPartReference(LinkAddressType link) const
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:64
auto && GetHeaderReference() const
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:58
TLinksOptions LinksOptionsType
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:10
const RawLinkIndexPart< LinkAddressType > & GetLinkIndexPartReference(LinkAddressType link) const
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:78
LinkAddressType EachUsage(LinkAddressType base, const ReadHandlerType &handler)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:206
static constexpr LinkAddressType Continue
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:17
LinkAddressType Search(LinkAddressType source, LinkAddressType target)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:144
bool FirstIsToTheRightOfSecond(LinkAddressType source, LinkAddressType target, LinkAddressType rootSource, LinkAddressType rootTarget)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:44
static constexpr LinkAddressType Break
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:16
std::byte * LinksDataParts
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:18
LinkAddressType CountUsages(LinkAddressType link)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:169
RawLinkDataPart< LinkAddressType > & GetLinkDataPartReference(LinkAddressType link)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:71
std::byte * Header
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:20
LinkAddressType GetTreeRoot()
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:32
typename LinksOptionsType::LinkType LinkType
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:13
static constexpr auto Constants
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:11
ExternalLinksSizeBalancedTreeMethodsBase(std::byte *linksDataParts, std::byte *linksIndexParts, std::byte *header)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:23
bool FirstIsToTheRightOfSecond(LinkAddressType first, LinkAddressType second)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:108
bool FirstIsToTheLeftOfSecond(LinkAddressType first, LinkAddressType second)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:99
std::byte * LinksIndexParts
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:19
RawLinkIndexPart< LinkAddressType > & GetLinkIndexPartReference(LinkAddressType link)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:85
auto GetLinkValues(LinkAddressType linkIndex)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:92
LinkAddressType GetBasePartValue(LinkAddressType link)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:38
LinkAddressType operator[](LinkAddressType index)
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:117
typename LinksOptionsType::WriteHandlerType WriteHandlerType
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:14
typename LinksOptionsType::ReadHandlerType ReadHandlerType
Definition ExternalLinksSizeBalancedTreeMethodsBase.h:15
Definition ExternalLinksRecursionlessSizeBalancedTreeMethodsBase.h:2