annotate final_main/src/getMinHeight.c @ 0:83f997abf3b5

first commit
author e155702
date Thu, 14 Feb 2019 16:51:50 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
83f997abf3b5 first commit
e155702
parents:
diff changeset
1 __code getMinHeight_stub(struct Context* context) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
2 goto getMinHeight(context, &context->data[Allocate]->allocate, &context->data[AkashaInfo]->akashaInfo);
83f997abf3b5 first commit
e155702
parents:
diff changeset
3 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
4
83f997abf3b5 first commit
e155702
parents:
diff changeset
5 __code getMinHeight(struct Context* context, struct Allocate* allocate, struct AkashaInfo* akashaInfo) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
6 const struct AkashaNode* akashaNode = akashaInfo->akashaNode;
83f997abf3b5 first commit
e155702
parents:
diff changeset
7
83f997abf3b5 first commit
e155702
parents:
diff changeset
8 if (akashaNode == NULL) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
9 allocate->size = sizeof(struct AkashaNode);
83f997abf3b5 first commit
e155702
parents:
diff changeset
10 allocator(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
11 akashaInfo->akashaNode = (struct AkashaNode*)context->data[context->dataNum];
83f997abf3b5 first commit
e155702
parents:
diff changeset
12
83f997abf3b5 first commit
e155702
parents:
diff changeset
13 akashaInfo->akashaNode->height = 1;
83f997abf3b5 first commit
e155702
parents:
diff changeset
14 akashaInfo->akashaNode->node = context->data[Tree]->tree.root;
83f997abf3b5 first commit
e155702
parents:
diff changeset
15
83f997abf3b5 first commit
e155702
parents:
diff changeset
16 goto getMaxHeight_stub(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
17 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
18
83f997abf3b5 first commit
e155702
parents:
diff changeset
19 const struct Node* node = akashaInfo->akashaNode->node;
83f997abf3b5 first commit
e155702
parents:
diff changeset
20 if (node->left == NULL && node->right == NULL) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
21 if (akashaInfo->minHeight > akashaNode->height) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
22 akashaInfo->minHeight = akashaNode->height;
83f997abf3b5 first commit
e155702
parents:
diff changeset
23 akashaInfo->akashaNode = akashaNode->nextAkashaNode;
83f997abf3b5 first commit
e155702
parents:
diff changeset
24 goto getMinHeight_stub(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
25 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
26 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
27
83f997abf3b5 first commit
e155702
parents:
diff changeset
28 akashaInfo->akashaNode = akashaInfo->akashaNode->nextAkashaNode;
83f997abf3b5 first commit
e155702
parents:
diff changeset
29
83f997abf3b5 first commit
e155702
parents:
diff changeset
30 if (node->left != NULL) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
31 allocate->size = sizeof(struct AkashaNode);
83f997abf3b5 first commit
e155702
parents:
diff changeset
32 allocator(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
33 struct AkashaNode* left = (struct AkashaNode*)context->data[context->dataNum];
83f997abf3b5 first commit
e155702
parents:
diff changeset
34 left->height = akashaNode->height+1;
83f997abf3b5 first commit
e155702
parents:
diff changeset
35 left->node = node->left;
83f997abf3b5 first commit
e155702
parents:
diff changeset
36 left->nextAkashaNode = akashaInfo->akashaNode;
83f997abf3b5 first commit
e155702
parents:
diff changeset
37 akashaInfo->akashaNode = left;
83f997abf3b5 first commit
e155702
parents:
diff changeset
38 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
39
83f997abf3b5 first commit
e155702
parents:
diff changeset
40 if (node->right != NULL) {
83f997abf3b5 first commit
e155702
parents:
diff changeset
41 allocate->size = sizeof(struct AkashaNode);
83f997abf3b5 first commit
e155702
parents:
diff changeset
42 allocator(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
43 struct AkashaNode* right = (struct AkashaNode*)context->data[context->dataNum];
83f997abf3b5 first commit
e155702
parents:
diff changeset
44 right->height = akashaNode->height+1;
83f997abf3b5 first commit
e155702
parents:
diff changeset
45 right->node = node->right;
83f997abf3b5 first commit
e155702
parents:
diff changeset
46 right->nextAkashaNode = akashaInfo->akashaNode;
83f997abf3b5 first commit
e155702
parents:
diff changeset
47 akashaInfo->akashaNode = right;
83f997abf3b5 first commit
e155702
parents:
diff changeset
48 }
83f997abf3b5 first commit
e155702
parents:
diff changeset
49
83f997abf3b5 first commit
e155702
parents:
diff changeset
50 goto getMinHeight_stub(context);
83f997abf3b5 first commit
e155702
parents:
diff changeset
51 }