Clean project structure.
This commit is contained in:
parent
78a4fa99ff
commit
947bf937fd
496 changed files with 206 additions and 137 deletions
76
src/base/core/data_structures/Tree.h
Normal file
76
src/base/core/data_structures/Tree.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
template<typename T>
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node(T data)
|
||||
: mData(data)
|
||||
{}
|
||||
|
||||
void addChild(std::unique_ptr<Node> child)
|
||||
{
|
||||
if(!mLeftChild)
|
||||
{
|
||||
mLeftChild = std::move(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
mRightChild = std::move(child);
|
||||
}
|
||||
}
|
||||
|
||||
bool isLeaf() const
|
||||
{
|
||||
return !mLeftChild && !mRightChild;
|
||||
}
|
||||
|
||||
T getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
Node* getLeftChild() const
|
||||
{
|
||||
return mLeftChild.get();
|
||||
}
|
||||
|
||||
Node* getRightChild() const
|
||||
{
|
||||
return mRightChild.get();
|
||||
}
|
||||
|
||||
private:
|
||||
T mData;
|
||||
unsigned char mTag{0};
|
||||
std::unique_ptr<Node> mLeftChild;
|
||||
std::unique_ptr<Node> mRightChild;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using NodePtr = std::unique_ptr<Node<T> >;
|
||||
|
||||
template<typename T>
|
||||
class Tree
|
||||
{
|
||||
public:
|
||||
Tree()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void addRootNode(NodePtr<T> root)
|
||||
{
|
||||
mRootNode = std::move(root);
|
||||
}
|
||||
|
||||
Node<T>* getRootNode() const
|
||||
{
|
||||
return mRootNode.get();
|
||||
}
|
||||
|
||||
private:
|
||||
NodePtr<T> mRootNode;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue