SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TTree< TVal > Class Template Reference

#include <ds.h>

Collaboration diagram for TTree< TVal >:

List of all members.

Public Member Functions

 TTree ()
 TTree (const TTree &Tree)
 TTree (TSIn &SIn)
void Save (TSOut &SOut) const
void LoadXml (const PXmlTok &XmlTok, const TStr &Nm="")
void SaveXml (TSOut &SOut, const TStr &Nm) const
TTreeoperator= (const TTree &Tree)
bool operator== (const TTree &Tree) const
bool operator< (const TTree &Tree) const
int GetPrimHashCd () const
int GetSecHashCd () const
int GetMemUsed () const
void Clr ()
int AddNode (const int &ParentNodeId, const TVal &NodeVal=TVal())
int AddRoot (const TVal &NodeVal=TVal())
int GetNodes () const
void GetNodeIdV (TIntV &NodeIdV, const int &NodeId=0)
int GetParentNodeId (const int &NodeId) const
int GetChildren (const int &NodeId) const
int GetChildNodeId (const int &NodeId, const int &ChildN) const
TVal & GetNodeVal (const int &NodeId)
void GenRandomTree (const int &Nodes, TRnd &Rnd)
void DelNode (const int &NodeId)
void CopyTree (const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
void WrTree (const int &NodeId=0, const int &Lev=0)

Private Attributes

TVec< TTriple< TInt, TIntV,
TVal > > 
NodeV

Detailed Description

template<class TVal>
class TTree< TVal >

Definition at line 3324 of file ds.h.


Constructor & Destructor Documentation

template<class TVal >
TTree< TVal >::TTree ( ) [inline]

Definition at line 3328 of file ds.h.

: NodeV(){}
template<class TVal >
TTree< TVal >::TTree ( const TTree< TVal > &  Tree) [inline]

Definition at line 3329 of file ds.h.

: NodeV(Tree.NodeV){}
template<class TVal >
TTree< TVal >::TTree ( TSIn SIn) [inline, explicit]

Definition at line 3330 of file ds.h.

: NodeV(SIn){}

Member Function Documentation

template<class TVal >
int TTree< TVal >::AddNode ( const int &  ParentNodeId,
const TVal &  NodeVal = TVal() 
) [inline]

Definition at line 3346 of file ds.h.

References TVec< TVal, TSizeTy >::Add(), IAssert, TVec< TVal, TSizeTy >::Len(), and TTree< TVal >::NodeV.

Referenced by TTree< TVal >::AddRoot(), and TTree< TVal >::CopyTree().

                                                                  {
    IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
    if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
    return NodeV.Add(TTriple<TInt, TIntV, TVal>(ParentNodeId, TIntV(), NodeVal));}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TVal >
int TTree< TVal >::AddRoot ( const TVal &  NodeVal = TVal()) [inline]

Definition at line 3350 of file ds.h.

References TTree< TVal >::AddNode().

                                         {
    return AddNode(-1, NodeVal);}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::Clr ( ) [inline]

Definition at line 3344 of file ds.h.

References TVec< TVal, TSizeTy >::Clr(), and TTree< TVal >::NodeV.

{NodeV.Clr();}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::CopyTree ( const int &  SrcNodeId,
TTree< TVal > &  DstTree,
const int &  DstParentNodeId = -1 
)

Definition at line 3405 of file ds.h.

References TTree< TVal >::AddNode().

                                                                                          {
  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
    int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
    if (ChildNodeId!=-1){
      CopyTree(ChildNodeId, DstTree, DstNodeId);
    }
  }
}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::DelNode ( const int &  NodeId)

Definition at line 3394 of file ds.h.

References TVec< TVal, TSizeTy >::SearchForw().

                                          {
  if (NodeId==0){
    Clr();
  } else {
    TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
    int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
    ChildNodeIdV[ChildNodeIdN]=-1;
  }
}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::GenRandomTree ( const int &  Nodes,
TRnd Rnd 
)

Definition at line 3382 of file ds.h.

References TRnd::GetUniDevInt().

                                                          {
  Clr();
  if (Nodes>0){
    AddRoot(TVal());
    for (int NodeN=1; NodeN<Nodes; NodeN++){
      int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
      AddNode(ParentNodeId, TVal());
    }
  }
}

Here is the call graph for this function:

template<class TVal >
int TTree< TVal >::GetChildNodeId ( const int &  NodeId,
const int &  ChildN 
) const [inline]

Definition at line 3357 of file ds.h.

References TTree< TVal >::NodeV.

{return NodeV[NodeId].Val2[ChildN];}
template<class TVal >
int TTree< TVal >::GetChildren ( const int &  NodeId) const [inline]

Definition at line 3356 of file ds.h.

References TVec< TVal, TSizeTy >::Len(), and TTree< TVal >::NodeV.

{return NodeV[NodeId].Val2.Len();}

Here is the call graph for this function:

template<class TVal >
int TTree< TVal >::GetMemUsed ( ) const [inline]

Definition at line 3342 of file ds.h.

References TVec< TVal, TSizeTy >::GetMemUsed(), and TTree< TVal >::NodeV.

{return NodeV.GetMemUsed();}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::GetNodeIdV ( TIntV NodeIdV,
const int &  NodeId = 0 
)

Definition at line 3369 of file ds.h.

References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Clr().

                                                             {
  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
  else if (GetParentNodeId(NodeId)==-1){return;}
  NodeIdV.Add(NodeId);
  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
    int ChildNodeId=GetChildNodeId(NodeId, ChildN);
    if (ChildNodeId!=-1){
      GetNodeIdV(NodeIdV, ChildNodeId);
    }
  }
}

Here is the call graph for this function:

template<class TVal >
int TTree< TVal >::GetNodes ( ) const [inline]

Definition at line 3353 of file ds.h.

References TVec< TVal, TSizeTy >::Len(), and TTree< TVal >::NodeV.

{return NodeV.Len();}

Here is the call graph for this function:

template<class TVal >
TVal& TTree< TVal >::GetNodeVal ( const int &  NodeId) [inline]

Definition at line 3358 of file ds.h.

References TTree< TVal >::NodeV.

{return NodeV[NodeId].Val3;}
template<class TVal >
int TTree< TVal >::GetParentNodeId ( const int &  NodeId) const [inline]

Definition at line 3355 of file ds.h.

References TTree< TVal >::NodeV.

{return NodeV[NodeId].Val1;} 
template<class TVal >
int TTree< TVal >::GetPrimHashCd ( ) const [inline]

Definition at line 3339 of file ds.h.

References TVec< TVal, TSizeTy >::GetPrimHashCd(), and TTree< TVal >::NodeV.

{return NodeV.GetPrimHashCd();}

Here is the call graph for this function:

template<class TVal >
int TTree< TVal >::GetSecHashCd ( ) const [inline]

Definition at line 3340 of file ds.h.

References TVec< TVal, TSizeTy >::GetSecHashCd(), and TTree< TVal >::NodeV.

{return NodeV.GetSecHashCd();}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::LoadXml ( const PXmlTok XmlTok,
const TStr Nm = "" 
)
template<class TVal >
bool TTree< TVal >::operator< ( const TTree< TVal > &  Tree) const [inline]

Definition at line 3337 of file ds.h.

{return false;}
template<class TVal >
TTree& TTree< TVal >::operator= ( const TTree< TVal > &  Tree) [inline]

Definition at line 3335 of file ds.h.

References TTree< TVal >::NodeV.

{if (this!=&Tree){NodeV=Tree.NodeV;} return *this;}
template<class TVal >
bool TTree< TVal >::operator== ( const TTree< TVal > &  Tree) const [inline]

Definition at line 3336 of file ds.h.

References TTree< TVal >::NodeV.

{return NodeV==Tree.NodeV;}
template<class TVal >
void TTree< TVal >::Save ( TSOut SOut) const [inline]

Definition at line 3331 of file ds.h.

References TTree< TVal >::NodeV, and TVec< TVal, TSizeTy >::Save().

{NodeV.Save(SOut);}

Here is the call graph for this function:

template<class TVal >
void TTree< TVal >::SaveXml ( TSOut SOut,
const TStr Nm 
) const
template<class TVal >
void TTree< TVal >::WrTree ( const int &  NodeId = 0,
const int &  Lev = 0 
)

Definition at line 3416 of file ds.h.

                                                         {
  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
    int ChildNodeId=GetChildNodeId(NodeId, ChildN);
    if (ChildNodeId!=-1){
      WrTree(ChildNodeId, Lev+1);
    }
  }
}

Member Data Documentation


The documentation for this class was generated from the following file: