Basic window class
parent
4a5c1799ce
commit
e2a358ffd1
|
@ -160,6 +160,7 @@ namespace blt {
|
||||||
if (parent == nullptr) {
|
if (parent == nullptr) {
|
||||||
m_root = nullptr;
|
m_root = nullptr;
|
||||||
} else {
|
} else {
|
||||||
|
// remove references to the nodes, we will add them later. We have a copy of the pointers which will be deleted.
|
||||||
if (parent->right == elementNode)
|
if (parent->right == elementNode)
|
||||||
parent->right = nullptr;
|
parent->right = nullptr;
|
||||||
else if (parent->left == elementNode)
|
else if (parent->left == elementNode)
|
||||||
|
@ -167,6 +168,7 @@ namespace blt {
|
||||||
else
|
else
|
||||||
throw binary_search_tree_error("Parent node doesn't own child!\n");
|
throw binary_search_tree_error("Parent node doesn't own child!\n");
|
||||||
}
|
}
|
||||||
|
// re-add all nodes to the tree, this is a terrible way of doing this, TODO.
|
||||||
for (auto* node : traverseNodes) {
|
for (auto* node : traverseNodes) {
|
||||||
if (node != elementNode) {
|
if (node != elementNode) {
|
||||||
if (parent == nullptr) {
|
if (parent == nullptr) {
|
||||||
|
@ -176,43 +178,6 @@ namespace blt {
|
||||||
delete(node);
|
delete(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*BST_node* inOrderSuccessor = elementNode->right;
|
|
||||||
BST_node* inOrderSuccessorParent = nullptr;
|
|
||||||
while (true){
|
|
||||||
// go all the way to the left subtree
|
|
||||||
while (inOrderSuccessor->left != nullptr) {
|
|
||||||
inOrderSuccessorParent = inOrderSuccessor;
|
|
||||||
inOrderSuccessor = inOrderSuccessor->left;
|
|
||||||
}
|
|
||||||
if (inOrderSuccessor->right != nullptr) {
|
|
||||||
inOrderSuccessorParent = inOrderSuccessor;
|
|
||||||
inOrderSuccessor = inOrderSuccessor->right;
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent != nullptr) {
|
|
||||||
if (parent->right == elementNode)
|
|
||||||
parent->right = inOrderSuccessor;
|
|
||||||
else if (parent->left == elementNode)
|
|
||||||
parent->left = inOrderSuccessor;
|
|
||||||
else
|
|
||||||
throw binary_search_tree_error("Parent node doesn't own child!\n");
|
|
||||||
} else
|
|
||||||
m_root = inOrderSuccessor;
|
|
||||||
// reconstruct the node's children
|
|
||||||
inOrderSuccessor->left = elementNode->left;
|
|
||||||
inOrderSuccessor->right = elementNode->right;
|
|
||||||
// delete the parent's reference to the moved node
|
|
||||||
if (inOrderSuccessorParent != nullptr) {
|
|
||||||
if (inOrderSuccessorParent->left == inOrderSuccessor)
|
|
||||||
inOrderSuccessorParent->left = nullptr;
|
|
||||||
else if (inOrderSuccessorParent->right == inOrderSuccessor)
|
|
||||||
inOrderSuccessorParent->right = nullptr;
|
|
||||||
else
|
|
||||||
throw binary_search_tree_error("Parent does not contain child!\n");
|
|
||||||
}
|
|
||||||
rebalance(parent);*/
|
|
||||||
} else {
|
} else {
|
||||||
auto replacementNode = elementNode->left != nullptr ? elementNode->left : elementNode->right;
|
auto replacementNode = elementNode->left != nullptr ? elementNode->left : elementNode->right;
|
||||||
if (parent == nullptr)
|
if (parent == nullptr)
|
||||||
|
@ -233,9 +198,8 @@ namespace blt {
|
||||||
return inOrderTraverse(m_root);
|
return inOrderTraverse(m_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline BST_node* debug() {
|
inline BST_node* findMin(){return findMin(m_root);}
|
||||||
return m_root;
|
inline BST_node* findMax(){return findMax(m_root);}
|
||||||
}
|
|
||||||
|
|
||||||
~node_binary_search_tree() {
|
~node_binary_search_tree() {
|
||||||
auto inOrder = inOrderTraverse();
|
auto inOrder = inOrderTraverse();
|
||||||
|
@ -245,14 +209,16 @@ namespace blt {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class flat_binary_search_tree {
|
class heap {
|
||||||
private:
|
private:
|
||||||
|
//TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using node_BST = node_binary_search_tree<T>;
|
using node_BST = node_binary_search_tree<T>;
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
using flat_binary_search_tree = heap<T>;
|
||||||
|
template<typename T>
|
||||||
using flat_BST = flat_binary_search_tree<T>;
|
using flat_BST = flat_binary_search_tree<T>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 13/01/23.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_TESTS_MAP_H
|
||||||
|
#define BLT_TESTS_MAP_H
|
||||||
|
|
||||||
|
template<typename K, typename V, typename HASH = std::hash<K>>
|
||||||
|
class hashmap {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //BLT_TESTS_MAP_H
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 16/01/23.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_WINDOW_H
|
||||||
|
#define BLT_WINDOW_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace blt {
|
||||||
|
|
||||||
|
class window {
|
||||||
|
public:
|
||||||
|
window() = default;
|
||||||
|
virtual void createWindow() = 0;
|
||||||
|
virtual void destroyWindow() = 0;
|
||||||
|
virtual ~window() = 0;
|
||||||
|
|
||||||
|
virtual bool setResizeable(bool resizeEnabled) = 0;
|
||||||
|
virtual bool setWindowSize(int width, int height) = 0;
|
||||||
|
virtual int getWidth() = 0;
|
||||||
|
virtual int getHeight() = 0;
|
||||||
|
|
||||||
|
virtual bool isKeyDown(int key) = 0;
|
||||||
|
virtual bool isMouseDown(int button) = 0;
|
||||||
|
// Function signature is window pointer to this, key press, pressed/released (true/false)
|
||||||
|
virtual void registerKeyListener(std::function<void(window*, int, bool)> listener) = 0;
|
||||||
|
// Function signature is window pointer to this, mouse button press, pressed/released (true/false)
|
||||||
|
virtual void registerMouseListener(std::function<void(window*, int, bool)> listener) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -4,4 +4,5 @@
|
||||||
* See LICENSE file for license detail
|
* See LICENSE file for license detail
|
||||||
*/
|
*/
|
||||||
#include <blt/std/system.h>
|
#include <blt/std/system.h>
|
||||||
#include <blt/std/binary_tree.h>
|
#include <blt/std/binary_tree.h>
|
||||||
|
#include <blt/std/map.h>
|
Loading…
Reference in New Issue