namespace lasd { /* ----- begin of struct NodeVec ----- */ template BinaryTreeVec::NodeVec::NodeVec(Data& dat, ulong idx, BinaryTreeVec* ref){ data = dat; index = idx; ReferenceToTree = ref; } template struct BinaryTreeVec::NodeVec& BinaryTreeVec::NodeVec::operator=(const BinaryTreeVec::NodeVec& node){ ReferenceToTree = node.ReferenceToTree; data = node.data; index = node.index; return *this; } template struct BinaryTreeVec::NodeVec& BinaryTreeVec::NodeVec::operator=(BinaryTreeVec::NodeVec&& node) noexcept{ std::swap(data, node.data); std::swap(index, node.index); std::swap(ReferenceToTree, node.ReferenceToTree); return *this; } template bool BinaryTreeVec::NodeVec::IsLeaf() const noexcept{ return (!HasLeftChild() && !HasRightChild()); } template bool BinaryTreeVec::NodeVec::HasLeftChild() const noexcept{ if( (index*2)+1 < ReferenceToTree->size){ return true; }else{ return false; } } template bool BinaryTreeVec::NodeVec::HasRightChild() const noexcept{ if((index*2)+2 < ReferenceToTree->size){ return true; }else{ return false; } } template struct BinaryTree::Node& BinaryTreeVec::NodeVec::LeftChild() const{ if(index*2+1 < ReferenceToTree->size) return *((ReferenceToTree->tree)[index*2+1]); else throw std::out_of_range("Left child does not exist!"); } template struct BinaryTree::Node& BinaryTreeVec::NodeVec::RightChild() const{ if(index*2+2 < ReferenceToTree->size) return *((ReferenceToTree->tree)[index*2+2]); else throw std::out_of_range("Right child does not exist!"); } /* ----- end of struct NodeVec ----- */ /* ----- begin of class BinaryTreeVec ----- */ template BinaryTreeVec::BinaryTreeVec(const LinearContainer& lc){ tree.Resize(lc.Size()); size = lc.Size(); for(ulong i=0 ; i::NodeVec* tmp = new BinaryTreeVec::NodeVec(lc[i], i, this); tree[i] = tmp; } } template BinaryTreeVec::BinaryTreeVec(const BinaryTreeVec& bt){ size = bt.size; tree.Resize(size); for(ulong i=0 ; i::NodeVec* tmp = new BinaryTreeVec::NodeVec( (bt.tree[i])->data , i, this); tree[i] = tmp; } } template BinaryTreeVec::BinaryTreeVec(BinaryTreeVec&& bt) noexcept{ std::swap(size,bt.size); std::swap(tree,bt.tree); for(ulong i=0 ; iReferenceToTree = this; } } template BinaryTreeVec::~BinaryTreeVec(){ Clear(); } template BinaryTreeVec& BinaryTreeVec::operator=(const BinaryTreeVec& bt){ size = bt.size; tree.Resize(size); for(ulong i=0 ; i::NodeVec((bt.tree[i])->data,i,this); tree[i] = tmp; } return *this; } template BinaryTreeVec& BinaryTreeVec::operator=(BinaryTreeVec&& bt) noexcept{ std::swap(size, bt.size); std::swap(tree, bt.tree); for(ulong i=0 ; iReferenceToTree = this; } return *this; } template bool BinaryTreeVec::operator==(const BinaryTreeVec& bt) const noexcept{ if(size==bt.size){ for(ulong i=0 ; idata != (bt.tree[i])->data ) return false; } return true; } return false; } template bool BinaryTreeVec::operator!=(const BinaryTreeVec& bt) const noexcept{ return !(*this == bt); } template struct BinaryTree::Node& BinaryTreeVec::Root() const{ if(size==0) throw std::length_error("Empty tree!"); return *(tree.Front()); } template void BinaryTreeVec::Clear(){ for(ulong i=0 ; i void BinaryTreeVec::MapBreadth(const MapFunctor func, void* par){ for(ulong i=0 ; idata, par); } } template void BinaryTreeVec::FoldBreadth(const FoldFunctor func, const void* par, void* acc) const{ for(ulong i=0 ; idata, par, acc); } } /* ************************************************************************** */ }