Browse Source

Implemented search functions.

Cameron Weinfurt 1 year ago
parent
commit
6e2fe6b97f
1 changed files with 41 additions and 0 deletions
  1. 41
    0
      tree_alloc.c

+ 41
- 0
tree_alloc.c View File

@@ -0,0 +1,41 @@
1
+#include "allocator_internal.h"
2
+
3
+TreeAlloc *insert_node_at(void *address, int padding, int align, int size) {
4
+	return NULL;
5
+}
6
+
7
+TreeAlloc *search_by_address(TreeAlloc *root, void *address) {
8
+	while (1) {
9
+		if (root < address) {
10
+			if (root->left)
11
+				root = root->left;
12
+			else
13
+				return root;
14
+		} else if (root > address) {
15
+			if (root->right)
16
+				root = root->right;
17
+			else
18
+				return root;
19
+		} else {
20
+			return root;
21
+		}
22
+	}
23
+}
24
+
25
+TreeAlloc *search_by_size(TreeAlloc *root, int padding, int align, int size) {
26
+	while (1) {
27
+		if (root->size < size) {
28
+			if (root->left)
29
+				root = root->left;
30
+			else
31
+				return root;
32
+		} else if (root->size > address) {
33
+			if (root->right)
34
+				root = root->right;
35
+			else
36
+				return root;
37
+		} else {
38
+			return root;
39
+		}
40
+	}
41
+}

Loading…
Cancel
Save