From 825c20627dae9d29f827fe767424056c8c15cfb9 Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Sat, 3 Feb 2024 17:15:51 +0200 Subject: [PATCH] Revert "doxygen update" This reverts commit 98445f42e02a9d39af19ae29729e6b47db385090. --- docs/html/avl__tree_8h_source 2.html | 437 ++++++++++++++++++++++++ docs/html/index.html | 2 +- docs/html/jump__search_8h_source 2.html | 119 +++++++ docs/latex/index.tex | 2 +- 4 files changed, 558 insertions(+), 2 deletions(-) create mode 100644 docs/html/avl__tree_8h_source 2.html create mode 100644 docs/html/jump__search_8h_source 2.html diff --git a/docs/html/avl__tree_8h_source 2.html b/docs/html/avl__tree_8h_source 2.html new file mode 100644 index 00000000..7c6f13f7 --- /dev/null +++ b/docs/html/avl__tree_8h_source 2.html @@ -0,0 +1,437 @@ + + + + + + + +AlgoPlus: /Users/spirosmag/Documents/AlgoPlus/src/classes/tree/avl_tree.h Source File + + + + + + + + + + + +
+
+ + + + + + + +
+
AlgoPlus v0.1.0 +
+
+
+ + + + + + + + + +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ + +
+
+
avl_tree.h
+
+
+
1#ifndef AVL_TREE_H
+
2#define AVL_TREE_H
+
3
+
4#ifdef __cplusplus
+
5#include "../../visualization/tree_visual/tree_visualization.h"
+
6#include <functional>
+
7#include <queue>
+
8#include <string>
+
9#include <vector>
+
10#endif
+
11
+
+
15template <typename T> class avl_tree {
+
16public:
+
+
22 explicit avl_tree(std::vector<T> __elements = {}) noexcept : root(nullptr) {
+
23 if (!__elements.empty()) {
+
24 for (T &x : __elements) {
+
25 this->insert(x);
+
26 }
+
27 }
+
28 }
+
+
29 ~avl_tree() noexcept {}
+
30
+
+
35 void insert(T key) {
+
36 root = __insert(root, key);
+
37 __size++;
+
38 }
+
+
39
+
+
44 void clear() {
+
45 root = nullptr;
+
46 __size = 0;
+
47 return;
+
48 }
+
+
49
+
55 bool search(T key) { return __search(root, key); }
+
56
+
57 class Iterator;
+
58
+
+ +
65 std::vector<T> ino = this->inorder();
+
66 return Iterator(0, ino);
+
67 }
+
+
68
+
+ +
75 std::vector<T> ino = this->inorder();
+
76 return Iterator(ino.size(), ino);
+
77 }
+
+
78
+
84 size_t size() { return __size; }
+
+
89 void remove(T key) {
+
90 root = __remove(root, key);
+
91 __size--;
+
92 }
+
+
93
+
+
98 std::vector<T> inorder() {
+
99 std::vector<T> path;
+
100 __inorder(
+
101 [&](std::shared_ptr<node> callbacked) {
+
102 path.push_back(callbacked->info);
+
103 },
+
104 root);
+
105 return path;
+
106 }
+
+
+
111 std::vector<T> preorder() {
+
112 std::vector<T> path;
+
113 __preorder(
+
114 [&](std::shared_ptr<node> callbacked) {
+
115 path.push_back(callbacked->info);
+
116 },
+
117 root);
+
118 return path;
+
119 }
+
+
+
124 std::vector<T> postorder() {
+
125 std::vector<T> path;
+
126 __postorder(
+
127 [&](std::shared_ptr<node> callbacked) {
+
128 path.push_back(callbacked->info);
+
129 },
+
130 root);
+
131 return path;
+
132 }
+
+
133
+
+
138 void visualize() {
+
139 std::string __generated = generate_visualization();
+
140 visualization::visualize(__generated);
+
141 }
+
+
142
+
143private:
+
151 typedef struct node {
+
152 T info;
+
153 int64_t height;
+
154 std::shared_ptr<node> left;
+
155 std::shared_ptr<node> right;
+
156 node(T key) : info(key), left(nullptr), right(nullptr), height(0) {}
+
157 } node;
+
158
+
159 std::shared_ptr<node> root;
+
160 size_t __size;
+
161
+
162 int64_t height(std::shared_ptr<node> root) {
+
163 if (root == nullptr)
+
164 return 0;
+
165 return 1 + std::max(height(root->left), height(root->right));
+
166 }
+
167
+
168 std::shared_ptr<node> createNode(T info) {
+
169 std::shared_ptr<node> nn = std::make_shared<node>(info);
+
170 return nn;
+
171 }
+
172
+
173 int64_t getBalance(std::shared_ptr<node> root) {
+
174 return height(root->left) - height(root->right);
+
175 }
+
176
+
177 std::shared_ptr<node> rightRotate(std::shared_ptr<node> root) {
+
178 std::shared_ptr<node> t = root->left;
+
179 std::shared_ptr<node> u = t->right;
+
180 t->right = root;
+
181 root->left = u;
+
182 return t;
+
183 }
+
184
+
185 std::shared_ptr<node> leftRotate(std::shared_ptr<node> root) {
+
186 std::shared_ptr<node> t = root->right;
+
187 std::shared_ptr<node> u = t->left;
+
188 t->left = root;
+
189 root->right = u;
+
190 return t;
+
191 }
+
192
+
193 std::shared_ptr<node> minValue(std::shared_ptr<node> root) {
+
194 if (root->left == nullptr)
+
195 return root;
+
196 return minValue(root->left);
+
197 }
+
198
+
199 std::shared_ptr<node> __insert(std::shared_ptr<node> root, T item) {
+
200 std::shared_ptr<node> nn = createNode(item);
+
201 if (root == nullptr)
+
202 return nn;
+
203 if (item < root->info)
+
204 root->left = __insert(root->left, item);
+
205 else
+
206 root->right = __insert(root->right, item);
+
207 int b = getBalance(root);
+
208 if (b > 1) {
+
209 if (getBalance(root->left) < 0)
+
210 root->left = leftRotate(root->left);
+
211 return rightRotate(root);
+
212 } else if (b < -1) {
+
213 if (getBalance(root->right) > 0)
+
214 root->right = rightRotate(root->right);
+
215 return leftRotate(root);
+
216 }
+
217 return root;
+
218 }
+
219
+
220 std::shared_ptr<node> __remove(std::shared_ptr<node> root, T key) {
+
221 if (root == nullptr)
+
222 return root;
+
223 if (key < root->info)
+
224 root->left = __remove(root->left, key);
+
225 else if (key > root->info)
+
226 root->right = __remove(root->right, key);
+
227
+
228 else {
+
229 if (!root->right) {
+
230 std::shared_ptr<node> temp = root->left;
+
231 root = nullptr;
+
232 return temp;
+
233 } else if (!root->left) {
+
234 std::shared_ptr<node> temp = root->right;
+
235 root = nullptr;
+
236 return temp;
+
237 }
+
238 std::shared_ptr<node> temp = minValue(root->right);
+
239 root->info = temp->info;
+
240 root->right = __remove(root->right, temp->info);
+
241 }
+
242 return root;
+
243 }
+
244
+
245 bool __search(std::shared_ptr<node> root, T key) {
+
246 while (root) {
+
247 if (root->info < key) {
+
248 root = root->right;
+
249 } else if (root->info > key) {
+
250 root = root->left;
+
251 } else {
+
252 return true;
+
253 }
+
254 }
+
255 return false;
+
256 }
+
257
+
258 void __inorder(std::function<void(std::shared_ptr<node>)> callback,
+
259 std::shared_ptr<node> root) {
+
260 if (root) {
+
261 __inorder(callback, root->left);
+
262 callback(root);
+
263 __inorder(callback, root->right);
+
264 }
+
265 }
+
266
+
267 void __postorder(std::function<void(std::shared_ptr<node>)> callback,
+
268 std::shared_ptr<node> root) {
+
269 if (root) {
+
270 __inorder(callback, root->left);
+
271 __inorder(callback, root->right);
+
272 callback(root);
+
273 }
+
274 }
+
275
+
276 void __preorder(std::function<void(std::shared_ptr<node>)> callback,
+
277 std::shared_ptr<node> root) {
+
278 if (root) {
+
279 callback(root);
+
280 __inorder(callback, root->left);
+
281 __inorder(callback, root->right);
+
282 }
+
283 }
+
284
+
285 std::string generate_visualization() {
+
286 std::string __generate = __inorder_gen(root);
+
287 return __generate;
+
288 }
+
289
+
290 std::string __inorder_gen(std::shared_ptr<node> root) {
+
291 std::string __s;
+
292 if (std::is_same_v<T, char> || std::is_same_v<T, std::string>) {
+
293 if (root->left) {
+
294 __s += root->info;
+
295 __s += "->";
+
296 __s += root->left->info;
+
297 __s += "\n";
+
298 __s += __inorder_gen(root->left);
+
299 }
+
300 if (root->right) {
+
301 __s += root->info;
+
302 __s += "->";
+
303 __s += root->right->info;
+
304 __s += "\n";
+
305 __s += __inorder_gen(root->right);
+
306 }
+
307 } else {
+
308 if (root->left) {
+
309 __s += std::to_string(root->info) + "->" +
+
310 std::to_string(root->left->info) + "\n" +
+
311 __inorder_gen(root->left);
+
312 }
+
313 if (root->right) {
+
314 __s += std::to_string(root->info) + "->" +
+
315 std::to_string(root->right->info) + "\n" +
+
316 __inorder_gen(root->right);
+
317 }
+
318 }
+
319 return __s;
+
320 }
+
321};
+
+
322
+
+
326template <typename T> class avl_tree<T>::Iterator {
+
327private:
+
328 std::vector<T> elements;
+
329 int64_t index;
+
330
+
331public:
+
+
337 explicit Iterator(const int64_t &index, std::vector<T> &els) noexcept
+
338 : index(index), elements(els) {}
+
+
339
+
+
346 Iterator &operator=(int64_t index) {
+
347 this->index = index;
+
348 return *(this);
+
349 }
+
+
350
+
+ +
357 if (this->index < elements.size()) {
+
358 this->index++;
+
359 }
+
360 return *(this);
+
361 }
+
+
362
+
+ +
369 Iterator it = *this;
+
370 ++*(this);
+
371 return it;
+
372 }
+
+
373
+
381 bool operator!=(const Iterator &it) { return index != it.index; }
+
382
+
388 T operator*() { return elements[index]; }
+
389};
+
+
390
+
391#endif
+
Iterator class.
Definition avl_tree.h:326
+
Iterator(const int64_t &index, std::vector< T > &els) noexcept
Construct a new Iterator object.
Definition avl_tree.h:337
+
bool operator!=(const Iterator &it)
operator != for type Iterator
Definition avl_tree.h:381
+
Iterator & operator++()
operator ++ for type Iterator
Definition avl_tree.h:356
+
T operator*()
operator * for type Iterator
Definition avl_tree.h:388
+
Iterator operator++(int)
operator ++ for type Iterator
Definition avl_tree.h:368
+
Iterator & operator=(int64_t index)
= operator for Iterator type
Definition avl_tree.h:346
+
Class for AVL tree.
Definition avl_tree.h:15
+
Iterator end()
pointer that points to end
Definition avl_tree.h:74
+
avl_tree(std::vector< T > __elements={}) noexcept
Contructor for AVL tree class.
Definition avl_tree.h:22
+
Iterator begin()
pointer that points to begin
Definition avl_tree.h:64
+
void clear()
clear function Erase all the nodes from the tree.
Definition avl_tree.h:44
+
void visualize()
visualize function
Definition avl_tree.h:138
+
bool search(T key)
search function.
Definition avl_tree.h:55
+
void remove(T key)
remove function.
Definition avl_tree.h:89
+
std::vector< T > postorder()
postorder function.
Definition avl_tree.h:124
+
std::vector< T > preorder()
preorder function.
Definition avl_tree.h:111
+
size_t size()
size function
Definition avl_tree.h:84
+
void insert(T key)
insert function.
Definition avl_tree.h:35
+
std::vector< T > inorder()
inorder function.
Definition avl_tree.h:98
+
+ + + + diff --git a/docs/html/index.html b/docs/html/index.html index 224fd490..45e94225 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -77,7 +77,7 @@

AlgoPlus is a C++ library that includes ready to use complex Data Structures.

Algoplus

-

Gitpod Ready-to-Code CodeQL CI Awesome CI GitHub repo size

+

Gitpod Ready-to-Code CodeQL CI Awesome CI

See the full documentation here

diff --git a/docs/html/jump__search_8h_source 2.html b/docs/html/jump__search_8h_source 2.html new file mode 100644 index 00000000..c462137f --- /dev/null +++ b/docs/html/jump__search_8h_source 2.html @@ -0,0 +1,119 @@ + + + + + + + +AlgoPlus: /Users/spirosmag/Documents/AlgoPlus/src/algorithms/searching/jump_search.h Source File + + + + + + + + + + + +
+
+ + + + + + + +
+
AlgoPlus v0.1.0 +
+
+
+ + + + + + + + + +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ + +
+
+
jump_search.h
+
+
+
1#ifndef JUMP_SEARCH_H
+
2#define JUMP_SEARCH_H
+
3
+
4#ifdef __cplusplus
+
5#include <iostream>
+
6#endif
+
7
+
8template <typename T> int64_t jump_search(std::vector<T> arr, T key) {
+
9 int64_t n = arr.size(), step = sqrt(arr.size()), prev = 0;
+
10 while (arr[std::min(step, n) - 1] < key) {
+
11 prev = step;
+
12 step += sqrt(n);
+
13 if (prev >= n) {
+
14 return -1; // out of bounds
+
15 }
+
16 }
+
17 while (arr[prev] < key) {
+
18 prev++;
+
19 if (prev == std::min(step, n)) {
+
20 return -1;
+
21 }
+
22 }
+
23 return (arr[prev] == key) ? prev : -1;
+
24}
+
25
+
26#endif
+
+ + + + diff --git a/docs/latex/index.tex b/docs/latex/index.tex index addd041a..2dd05c42 100644 --- a/docs/latex/index.tex +++ b/docs/latex/index.tex @@ -6,7 +6,7 @@ \chapter{Algoplus\{BETA Version\}} -\href{https://gitpod.io/\#https://github.com/CSRT-NTUA/AlgoPlus}{\texttt{ }} \href{https://github.com/CSRT-NTUA/AlgoPlus/actions/workflows/codeql.yml}{\texttt{ }} \href{https://github.com/CSRT-NTUA/AlgoPlus/actions?query=workflow\%3A\%22Awesome+CI+Workflow\%22}{\texttt{ }} \hypertarget{index_autotoc_md5}{}\doxysubsection{\texorpdfstring{{\bfseries{See the full documentation \href{https://csrt-ntua.github.io/AlgoPlus/}{\texttt{ here}}}}}{{\bfseries{See the full documentation \href{https://csrt-ntua.github.io/AlgoPlus/}{\texttt{ here}}}}}}\label{index_autotoc_md5} +\href{https://gitpod.io/\#https://github.com/CSRT-NTUA/AlgoPlus}{\texttt{ }} \href{https://github.com/CSRT-NTUA/AlgoPlus/actions/workflows/codeql.yml}{\texttt{ }} \href{https://github.com/CSRT-NTUA/AlgoPlus/actions?query=workflow\%3A\%22Awesome+CI+Workflow\%22}{\texttt{ }}\hypertarget{index_autotoc_md5}{}\doxysubsection{\texorpdfstring{{\bfseries{See the full documentation \href{https://csrt-ntua.github.io/AlgoPlus/}{\texttt{ here}}}}}{{\bfseries{See the full documentation \href{https://csrt-ntua.github.io/AlgoPlus/}{\texttt{ here}}}}}}\label{index_autotoc_md5} \hypertarget{index_autotoc_md6}{}\doxysubsection{\texorpdfstring{{\bfseries{\href{https://discord.gg/M9nYv4MHz6}{\texttt{ Join}} our Discord}}}{{\bfseries{\href{https://discord.gg/M9nYv4MHz6}{\texttt{ Join}} our Discord}}}}\label{index_autotoc_md6} \hypertarget{index_autotoc_md7}{}\doxysubsection{\texorpdfstring{Example\+:}{Example\+:}}\label{index_autotoc_md7}