/* Copyright by Matthias Hoechsmann (C) 2002-2004 ===================================== You may use, copy and distribute this file freely as long as you - do not change the file, - leave this copyright notice in the file, - do not make any profit with the distribution of this file - give credit where credit is due You are not allowed to copy or distribute this file otherwise The commercial usage and distribution of this file is prohibited Please report bugs and suggestions to */ #include "misc.h" #include "ppforestbase.h" #include "debug.h" #include #include #include #include "misc.t.cpp" /* ****************************************** */ /* Constructor and Destructor functions */ /* ****************************************** */ PPForestBase::PPForestBase(size_type size) { initialize(size); }; PPForestBase::PPForestBase(const PPForestBase &ppfBase) { initialize(ppfBase.size()); memcpy(m_rb,ppfBase.m_rb,sizeof(size_type)*m_size); memcpy(m_noc,ppfBase.m_noc,sizeof(size_type)*m_size); memcpy(m_sumUpCSF,ppfBase.m_sumUpCSF,sizeof(size_type)*(m_size+1)); memcpy(m_rmb,ppfBase.m_rmb,sizeof(size_type)*m_size); m_isSumUpCSFValid=ppfBase.m_isSumUpCSFValid; m_isRMBValid=ppfBase.m_isRMBValid; } PPForestBase::~PPForestBase() { DELETE_ARRAY(m_rb); DELETE_ARRAY(m_noc); DELETE_ARRAY(m_sumUpCSF); DELETE_ARRAY(m_rmb); }; /* ****************************************** */ /* Private functions */ /* ****************************************** */ PPForestBase::size_type PPForestBase::countLeaves(size_type i) const { size_type numLeaves=0; for(size_type k=0;k=0;i--) { if(m_rb[i]) m_rmb[i]=m_rmb[m_rb[i]]; else m_rmb[i]=i; } m_isRMBValid=true; } void PPForestBase::initialize(size_type size) { m_size=size; m_rb=new size_type[size]; m_noc=new size_type[size]; m_sumUpCSF=new size_type[size+1]; m_rmb=new size_type[size]; m_isSumUpCSFValid=false; m_isRMBValid=false; } /* ****************************************** */ /* Public functions */ /* ****************************************** */ PPForestBase::size_type PPForestBase::rb(size_type i, size_type k) const { if(k==0) return i; else return rb(rb(i),k-1); } PPForestBase::size_type PPForestBase::maxDegree() const { size_type degree=0; for(size_type i=0;i