From 8e3c9b253d3b583086da9ddc29d995fdf887482b Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 20 Aug 2018 22:49:09 +0200 Subject: [PATCH] [DEV] add some fucntions on tree --- etk/FlatTree.hpp | 23 ++++++++++++++++++++++- etk/TreeNode.hpp | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/etk/FlatTree.hpp b/etk/FlatTree.hpp index 950b77f..765fc69 100644 --- a/etk/FlatTree.hpp +++ b/etk/FlatTree.hpp @@ -208,7 +208,7 @@ namespace etk { }; #endif private: - etk::Vector>> m_data; + etk::Vector>> 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>& _node) { if (_node == null) { diff --git a/etk/TreeNode.hpp b/etk/TreeNode.hpp index d5cf3aa..f4b7734 100644 --- a/etk/TreeNode.hpp +++ b/etk/TreeNode.hpp @@ -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; + } }; }