SNAP Library 4.1, Developer Reference  2018-07-26 16:30:42
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 2461 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 2465 of file ds.h.

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

Definition at line 2466 of file ds.h.

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

Definition at line 2467 of file ds.h.

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

Member Function Documentation

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

Definition at line 2483 of file ds.h.

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

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

2483  {
2484  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
2485  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
2486  return NodeV.Add(TTriple<TInt, TIntV, TVal>(ParentNodeId, TIntV(), NodeVal));}
#define IAssert(Cond)
Definition: bd.h:262
Definition: ds.h:130
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2463
TVec< TInt > TIntV
Definition: ds.h:1594

Here is the caller graph for this function:

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

Definition at line 2487 of file ds.h.

References TTree< TVal >::AddNode().

2487  {
2488  return AddNode(-1, NodeVal);}
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2483

Here is the call graph for this function:

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

Definition at line 2481 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2542 of file ds.h.

References TTree< TVal >::AddNode().

2542  {
2543  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2544  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2545  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2546  if (ChildNodeId!=-1){
2547  CopyTree(ChildNodeId, DstTree, DstNodeId);
2548  }
2549  }
2550 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2483
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2494
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:2542
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:2495
int GetChildren(const int &NodeId) const
Definition: ds.h:2493

Here is the call graph for this function:

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

Definition at line 2531 of file ds.h.

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

2531  {
2532  if (NodeId==0){
2533  Clr();
2534  } else {
2535  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2536  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
2537  ChildNodeIdV[ChildNodeIdN]=-1;
2538  }
2539 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2492
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2463
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1552
void Clr()
Definition: ds.h:2481

Here is the call graph for this function:

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

Definition at line 2519 of file ds.h.

References TRnd::GetUniDevInt().

2519  {
2520  Clr();
2521  if (Nodes>0){
2522  AddRoot(TVal());
2523  for (int NodeN=1; NodeN<Nodes; NodeN++){
2524  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
2525  AddNode(ParentNodeId, TVal());
2526  }
2527  }
2528 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2483
int GetNodes() const
Definition: ds.h:2490
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:2487
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
void Clr()
Definition: ds.h:2481

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

References TTree< TVal >::NodeV.

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

Definition at line 2493 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2479 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2506 of file ds.h.

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

2506  {
2507  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
2508  else if (GetParentNodeId(NodeId)==-1){return;}
2509  NodeIdV.Add(NodeId);
2510  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2511  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2512  if (ChildNodeId!=-1){
2513  GetNodeIdV(NodeIdV, ChildNodeId);
2514  }
2515  }
2516 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2492
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2494
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:2506
int GetNodes() const
Definition: ds.h:2490
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
int GetChildren(const int &NodeId) const
Definition: ds.h:2493
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

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

Definition at line 2490 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2495 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2492 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2476 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2477 of file ds.h.

References TTree< TVal >::NodeV.

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

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

Definition at line 2472 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2473 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2468 of file ds.h.

References TTree< TVal >::NodeV.

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

2553  {
2554  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
2555  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
2556  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2557  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2558  if (ChildNodeId!=-1){
2559  WrTree(ChildNodeId, Lev+1);
2560  }
2561  }
2562 }
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2494
int GetChildren(const int &NodeId) const
Definition: ds.h:2493
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:2553

Member Data Documentation


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