SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TTree< TVal > Class Template Reference

#include <ds.h>

Collaboration diagram for TTree< TVal >:

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 3338 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 3342 of file ds.h.

3342 : NodeV(){}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
TTree< TVal >::TTree ( const TTree< TVal > &  Tree)
inline

Definition at line 3343 of file ds.h.

3343 : NodeV(Tree.NodeV){}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
TTree< TVal >::TTree ( TSIn SIn)
inlineexplicit

Definition at line 3344 of file ds.h.

3344 : NodeV(SIn){}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340

Member Function Documentation

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

Definition at line 3360 of file ds.h.

References IAssert, and TTree< TVal >::NodeV.

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

3360  {
3361  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
3362  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
3363  return NodeV.Add(TTriple<TInt, TIntV, TVal>(ParentNodeId, TIntV(), NodeVal));}
#define IAssert(Cond)
Definition: bd.h:262
Definition: ds.h:129
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
TVec< TInt > TIntV
Definition: ds.h:2473

Here is the caller graph for this function:

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

Definition at line 3364 of file ds.h.

References TTree< TVal >::AddNode().

3364  {
3365  return AddNode(-1, NodeVal);}
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:3360

Here is the call graph for this function:

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

Definition at line 3358 of file ds.h.

References TTree< TVal >::NodeV.

3358 {NodeV.Clr();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
void TTree< TVal >::CopyTree ( const int &  SrcNodeId,
TTree< TVal > &  DstTree,
const int &  DstParentNodeId = -1 
)

Definition at line 3419 of file ds.h.

References TTree< TVal >::AddNode().

3419  {
3420  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
3421  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
3422  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
3423  if (ChildNodeId!=-1){
3424  CopyTree(ChildNodeId, DstTree, DstNodeId);
3425  }
3426  }
3427 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:3360
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:3371
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:3419
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:3372
int GetChildren(const int &NodeId) const
Definition: ds.h:3370

Here is the call graph for this function:

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

Definition at line 3408 of file ds.h.

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

3408  {
3409  if (NodeId==0){
3410  Clr();
3411  } else {
3412  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
3413  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
3414  ChildNodeIdV[ChildNodeIdN]=-1;
3415  }
3416 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:3369
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1440
void Clr()
Definition: ds.h:3358

Here is the call graph for this function:

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

Definition at line 3396 of file ds.h.

References TRnd::GetUniDevInt().

3396  {
3397  Clr();
3398  if (Nodes>0){
3399  AddRoot(TVal());
3400  for (int NodeN=1; NodeN<Nodes; NodeN++){
3401  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
3402  AddNode(ParentNodeId, TVal());
3403  }
3404  }
3405 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:3360
int GetNodes() const
Definition: ds.h:3367
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:3364
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
void Clr()
Definition: ds.h:3358

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 3371 of file ds.h.

References TTree< TVal >::NodeV.

3371 {return NodeV[NodeId].Val2[ChildN];}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
int TTree< TVal >::GetChildren ( const int &  NodeId) const
inline

Definition at line 3370 of file ds.h.

References TTree< TVal >::NodeV.

3370 {return NodeV[NodeId].Val2.Len();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
int TTree< TVal >::GetMemUsed ( ) const
inline

Definition at line 3356 of file ds.h.

References TTree< TVal >::NodeV.

3356 {return NodeV.GetMemUsed();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
void TTree< TVal >::GetNodeIdV ( TIntV NodeIdV,
const int &  NodeId = 0 
)

Definition at line 3383 of file ds.h.

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

3383  {
3384  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
3385  else if (GetParentNodeId(NodeId)==-1){return;}
3386  NodeIdV.Add(NodeId);
3387  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3388  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3389  if (ChildNodeId!=-1){
3390  GetNodeIdV(NodeIdV, ChildNodeId);
3391  }
3392  }
3393 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:3369
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:3371
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:3383
int GetNodes() const
Definition: ds.h:3367
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
int GetChildren(const int &NodeId) const
Definition: ds.h:3370
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559

Here is the call graph for this function:

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

Definition at line 3367 of file ds.h.

References TTree< TVal >::NodeV.

3367 {return NodeV.Len();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
TVal& TTree< TVal >::GetNodeVal ( const int &  NodeId)
inline

Definition at line 3372 of file ds.h.

References TTree< TVal >::NodeV.

3372 {return NodeV[NodeId].Val3;}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
int TTree< TVal >::GetParentNodeId ( const int &  NodeId) const
inline

Definition at line 3369 of file ds.h.

References TTree< TVal >::NodeV.

3369 {return NodeV[NodeId].Val1;}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
int TTree< TVal >::GetPrimHashCd ( ) const
inline

Definition at line 3353 of file ds.h.

References TTree< TVal >::NodeV.

3353 {return NodeV.GetPrimHashCd();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
int TTree< TVal >::GetSecHashCd ( ) const
inline

Definition at line 3354 of file ds.h.

References TTree< TVal >::NodeV.

3354 {return NodeV.GetSecHashCd();}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
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 3351 of file ds.h.

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

Definition at line 3349 of file ds.h.

References TTree< TVal >::NodeV.

3349 {if (this!=&Tree){NodeV=Tree.NodeV;} return *this;}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
bool TTree< TVal >::operator== ( const TTree< TVal > &  Tree) const
inline

Definition at line 3350 of file ds.h.

References TTree< TVal >::NodeV.

3350 {return NodeV==Tree.NodeV;}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
template<class TVal >
void TTree< TVal >::Save ( TSOut SOut) const
inline

Definition at line 3345 of file ds.h.

References TTree< TVal >::NodeV.

3345 {NodeV.Save(SOut);}
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:3340
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 3430 of file ds.h.

3430  {
3431  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
3432  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
3433  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
3434  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
3435  if (ChildNodeId!=-1){
3436  WrTree(ChildNodeId, Lev+1);
3437  }
3438  }
3439 }
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:3371
int GetChildren(const int &NodeId) const
Definition: ds.h:3370
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:3430

Member Data Documentation


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