From 7f7a985ed684efbc39286cdb538c54ae4fad4bc9 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Sun, 7 Nov 2021 01:38:17 +0800 Subject: [PATCH] makefile: reasonable way of adding compile options --- Makefile.flags | 4 ---- config.h | 14 ++++++++++++++ main.h | 2 ++ util/tree.c | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 config.h diff --git a/Makefile.flags b/Makefile.flags index 238e84d..0fad1ee 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -2,10 +2,6 @@ .SILENT: -# HELOS_RUNTIME_QUIET Supress on-screen kernel output (not supressing serial output) -export BUILD_OPTIONS = -DHELOS_RUNTIME_QUIET - - FLAGS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) SELF_DIR = $(dir $@) diff --git a/config.h b/config.h new file mode 100644 index 0000000..0cdf06b --- /dev/null +++ b/config.h @@ -0,0 +1,14 @@ +// config.h: Compile flags + +#pragma once + + +// Supress all screen output on boot. +// Serial output is not supressed. +#define HELOS_RUNTIME_QUIET + + +// util/tree.h uses a Treap model for balancing. +// +// If no TREE_TYPE flags are defined, no balancing is employed. +#define HELOS_UTIL_TREE_TYPE_TREAP diff --git a/main.h b/main.h index 75d9274..baaea7d 100644 --- a/main.h +++ b/main.h @@ -1,5 +1,7 @@ #pragma once +#include "config.h" + #include #include diff --git a/util/tree.c b/util/tree.c index 5d4db32..d626aaf 100644 --- a/util/tree.c +++ b/util/tree.c @@ -50,7 +50,11 @@ SYSV_ABI static tree_Node *__tree_InsertNodes(tree_Tree *t, tree_Node *node, tre if (!node) { if (added) *added = true; +#ifdef HELOS_UTIL_TREE_TYPE_TREAP return *result = __tree_NewNode(t, key, father, random_Rand() ^ key); +#else + return *result = __tree_NewNode(t, key, father, 0); +#endif } else if (key < node->key) { node->left = __tree_InsertNodes(t, node->left, node, key, result, added); return node; @@ -69,8 +73,10 @@ tree_Node *tree_InsertNode(tree_Tree *t, uintptr_t key, bool *added) { tree_Node *result; t->root = __tree_InsertNodes(t, t->root, 0, key, &result, added); +#ifdef HELOS_UTIL_TREE_TYPE_TREAP if (*added) __tree_treap_Adjust(result, &t->root); +#endif return result; } @@ -105,11 +111,16 @@ void *tree_Find(tree_Tree *t, uintptr_t key) { void tree_Delete(tree_Tree *t, tree_Node *node) { +#ifdef HELOS_UTIL_TREE_TYPE_TREAP while (node->left && node->right) if (node->left->internal < node->right->internal) __tree_Rotate(node->left, &t->root); else __tree_Rotate(node->right, &t->root); +#else + while (node->left) + __tree_Rotate(node->left, &t->root); +#endif if (node == t->root) t->root = (node->left ? node->left : node->right);