From 41e0791a53ce0682c005a1931f4f9ac49a200767 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 4 Mar 2024 10:58:42 -0500 Subject: [PATCH] sexy --- include/lilfbtf/lilfbtf.h | 2 +- libs/BLT | 2 +- tests/include/lilfbtf/test2.h | 35 +++++++ tests/src/main.cpp | 7 +- tests/src/tests2.cpp | 188 ++++++++++++++++++++++++++++++++++ 5 files changed, 228 insertions(+), 6 deletions(-) create mode 100644 tests/include/lilfbtf/test2.h create mode 100644 tests/src/tests2.cpp diff --git a/include/lilfbtf/lilfbtf.h b/include/lilfbtf/lilfbtf.h index 533d559..22ffdda 100644 --- a/include/lilfbtf/lilfbtf.h +++ b/include/lilfbtf/lilfbtf.h @@ -19,7 +19,7 @@ #ifndef LILFBTF5_LILFBTF_H #define LILFBTF5_LILFBTF_H -namespace lilfb +namespace fb { diff --git a/libs/BLT b/libs/BLT index 148768d..b7d69bd 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit 148768d6903884feb92066f316915f6ebf97f464 +Subproject commit b7d69bdcbb4e9bb61650c7d85e7ae444cb21ed74 diff --git a/tests/include/lilfbtf/test2.h b/tests/include/lilfbtf/test2.h new file mode 100644 index 0000000..b95c04c --- /dev/null +++ b/tests/include/lilfbtf/test2.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LILFBTF5_TEST2_H +#define LILFBTF5_TEST2_H + +namespace fb +{ + + void execute(); + void funny(); + + inline void execute_tests() + { + execute(); + } + +} + +#endif //LILFBTF5_TEST2_H diff --git a/tests/src/main.cpp b/tests/src/main.cpp index e31f7b7..7b3f4dc 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include struct data { float f; @@ -24,8 +24,8 @@ int main(int argc, const char** argv) std::cout << static_cast(buffer) << " ' " << remaining_bytes << std::endl; void_ptr = reinterpret_cast(&buffer[offset]); new_ptr = static_cast(std::align(alignof(char), sizeof(char), void_ptr, remaining_bytes)); - std::cout << static_cast(new_ptr) << " : " << remaining_bytes << " | " << (buffer - new_ptr + sizeof(char)) << std::endl; - offset += (buffer - new_ptr + sizeof(char)); + std::cout << static_cast(new_ptr) << " : " << remaining_bytes << " | " << (buffer - new_ptr + 1) << std::endl; + offset += (buffer - new_ptr + 1); remaining_bytes = size - offset; void_ptr = reinterpret_cast(&buffer[offset]); @@ -33,7 +33,6 @@ int main(int argc, const char** argv) std::cout << static_cast(new_ptr) << " : " << remaining_bytes << " | " << (buffer - new_ptr + sizeof(data)) << std::endl; offset += (buffer - new_ptr + sizeof(data)); - delete[](buffer); std::cout << "Hello, World!" << std::endl; diff --git a/tests/src/tests2.cpp b/tests/src/tests2.cpp new file mode 100644 index 0000000..2aaf9c1 --- /dev/null +++ b/tests/src/tests2.cpp @@ -0,0 +1,188 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include "blt/std/ranges.h" +#include "blt/std/allocator.h" +#include +#include +#include + +namespace fb +{ + template + class tree + { + using index = blt::u32; + private: + struct node + { + index parent; + std::array children; + std::function)> func; + }; + std::vector nodes; + + public: + }; + + void execute() + { + + } + + enum class type_t + { + ADD, SUB, MUL, VALUE + }; + + type_t random_type() + { + static std::random_device dev; + static std::mt19937_64 engine{dev()}; + static std::uniform_int_distribution dist(0, 3); + return static_cast(dist(engine)); + } + + type_t random_type_sub() + { + static std::random_device dev; + static std::mt19937_64 engine{dev()}; + static std::uniform_int_distribution dist(0, 2); + return static_cast(dist(engine)); + } + + double random_value() + { + static std::random_device dev; + static std::mt19937_64 engine{dev()}; + static std::uniform_real_distribution dist(-10.0, 10.0); + return dist(engine); + } + + bool choice() + { + static std::random_device dev; + static std::mt19937_64 engine{dev()}; + static std::uniform_int_distribution dist(0, 1); + return dist(engine); + } + + std::array arg_c = {2, 2, 2, 0}; + + class tree1 + { + private: + struct node_t + { + std::array children{}; + double value = 0; + blt::i32 argc; + type_t type; + + explicit node_t(type_t type): argc(arg_c[static_cast(type)]), type(type) + { + if (type == type_t::VALUE) + value = random_value(); + } + + void evaluate() + { + switch (type) + { + case type_t::ADD: + value = children[0]->value + children[1]->value; + return; + case type_t::SUB: + value = children[0]->value - children[1]->value; + return; + case type_t::MUL: + value = children[0]->value * children[1]->value; + return; + case type_t::VALUE: + return; + } + } + + double evaluate_tree() + { + std::stack nodes; + std::stack node_stack; + + nodes.push(this); + + while (!nodes.empty()) + { + auto* top = nodes.top(); + node_stack.push(top); + nodes.pop(); + for (blt::i32 i = 0; i < top->argc; i++) + nodes.push(top->children[i]); + } + + while (!node_stack.empty()) + { + node_stack.top()->evaluate(); + node_stack.pop(); + } + return value; + } + }; + + node_t* root = nullptr; + public: + blt::bump_allocator alloc{sizeof(node_t) * 8192}; + + void create(blt::size_t size) + { + root = alloc.emplace(random_type()); + std::stack> stack; + stack.emplace(root, 0); + while (!stack.empty()) + { + auto top = stack.top(); + auto* node = top.first; + auto depth = top.second; + stack.pop(); + for (blt::i32 i = 0; i < node->argc; i++) + { + auto& assignment = node->children[i]; + if (choice()) + assignment = alloc.emplace(random_type()); + else + assignment = alloc.emplace(random_type_sub()); + if (depth < size) + stack.emplace(assignment, depth + 1); + } + } + } + + double evaluate() + { + return root->evaluate_tree(); + } + }; + + void funny() + { + tree1 love; + love.create(10); + BLT_TRACE(love.evaluate()); + } +} \ No newline at end of file