From 8aa071eb858b6061a82ed1f95a28b808cae15723 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 26 Dec 2022 00:31:00 -0500 Subject: [PATCH] Basic Queue --- include/blt/profiling/profiler.h | 32 +++++++++-------- include/blt/std/queues.h | 61 ++++++++++++++++++++++++++++++++ src/blt/profiling/profiler.cpp | 6 +++- src/blt/std/queues.cpp | 10 ++++++ 4 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 include/blt/std/queues.h create mode 100644 src/blt/std/queues.cpp diff --git a/include/blt/profiling/profiler.h b/include/blt/profiling/profiler.h index 3cba2e0..d408882 100644 --- a/include/blt/profiling/profiler.h +++ b/include/blt/profiling/profiler.h @@ -10,20 +10,22 @@ #include #include -struct CapturePoint { - long point; -}; - -struct CaptureInterval { - CapturePoint start; - CapturePoint end; -}; - -template -class Profiler { - private: - MAP_TYPE* intervals; - MAP_TYPE* points = new MAP_TYPE(); -}; +namespace BLT { + struct CapturePoint { + long point; + }; + + struct CaptureInterval { + CapturePoint start; + CapturePoint end; + }; + + template + class Profiler { + private: + MAP_TYPE intervals; + MAP_TYPE points; + }; +} #endif //BLT_PROFILER_H diff --git a/include/blt/std/queues.h b/include/blt/std/queues.h new file mode 100644 index 0000000..1dcec2d --- /dev/null +++ b/include/blt/std/queues.h @@ -0,0 +1,61 @@ +/* + * Created by Brett on 26/12/22. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_QUEUES_H +#define BLT_QUEUES_H + +namespace BLT { + + template + struct node { + T t; + node* next; + }; + + template + class flat_queue { + + }; + + template + class node_queue { + private: + node* head; + public: + + void insert(T t) { + auto newNode = new node(t, nullptr); + if (head == nullptr) + head = newNode; + else { + newNode->next = head; + head = newNode; + } + } + + [[nodiscard]] T front() const { + return head->t; + } + + void pop() { + auto nextNode = head->next; + delete(head); + head = nextNode; + } + + ~node_queue() { + auto next = head; + while (next != nullptr){ + auto nextNode = next->next; + delete(next); + next = nextNode; + } + } + }; + +} + +#endif //BLT_QUEUES_H diff --git a/src/blt/profiling/profiler.cpp b/src/blt/profiling/profiler.cpp index 0375e8e..34f21cd 100644 --- a/src/blt/profiling/profiler.cpp +++ b/src/blt/profiling/profiler.cpp @@ -3,4 +3,8 @@ * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ -#include \ No newline at end of file +#include + +namespace BLT { + +} \ No newline at end of file diff --git a/src/blt/std/queues.cpp b/src/blt/std/queues.cpp new file mode 100644 index 0000000..25ab7f0 --- /dev/null +++ b/src/blt/std/queues.cpp @@ -0,0 +1,10 @@ +/* + * Created by Brett on 26/12/22. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ +#include + +namespace BLT { + +} \ No newline at end of file