[DEV] add some fucntions on tree

This commit is contained in:
Edouard DUPIN 2018-08-20 22:49:09 +02:00
parent 3101490a3d
commit 8e3c9b253d
2 changed files with 29 additions and 1 deletions

View File

@ -208,7 +208,7 @@ namespace etk {
};
#endif
private:
etk::Vector<const ememory::SharedPtr<etk::TreeNode<ETK_TREENODE_TYPE>>> m_data;
etk::Vector<ememory::SharedPtr<etk::TreeNode<ETK_TREENODE_TYPE>>> m_data;
public:
FlatTree() {
@ -217,6 +217,27 @@ namespace etk {
m_data.clear();
append(_root);
}
size_t size() const {
return m_data.size();
}
auto begin() const {
return m_data.begin();
}
auto begin() {
return m_data.begin();
}
auto end() const {
return m_data.end();
}
auto end() {
return m_data.end();
}
auto operator[] (size_t _pos) {
return m_data[_pos];
}
auto operator[] (size_t _pos) const {
return m_data[_pos];
}
private:
void append(const ememory::SharedPtr<etk::TreeNode<ETK_TREENODE_TYPE>>& _node) {
if (_node == null) {

View File

@ -124,6 +124,13 @@ namespace etk {
}
return out;
}
size_t countToRoot() {
auto parent = m_parent.lock();
if (parent == null) {
return 0;
}
return parent->countToRoot() + 1;
}
};
}