SNAP Library 2.4, Developer Reference  2015-05-11 19:40:56
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 2347 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 2351 of file ds.h.

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

Definition at line 2352 of file ds.h.

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

Definition at line 2353 of file ds.h.

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

Member Function Documentation

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

Definition at line 2369 of file ds.h.

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

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

2369  {
2370  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
2371  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
2372  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:2349
TVec< TInt > TIntV
Definition: ds.h:1482

Here is the caller graph for this function:

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

Definition at line 2373 of file ds.h.

References TTree< TVal >::AddNode().

2373  {
2374  return AddNode(-1, NodeVal);}
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2369

Here is the call graph for this function:

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

Definition at line 2367 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2428 of file ds.h.

References TTree< TVal >::AddNode().

2428  {
2429  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2430  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2431  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2432  if (ChildNodeId!=-1){
2433  CopyTree(ChildNodeId, DstTree, DstNodeId);
2434  }
2435  }
2436 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2369
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2380
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:2428
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:2381
int GetChildren(const int &NodeId) const
Definition: ds.h:2379

Here is the call graph for this function:

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

Definition at line 2417 of file ds.h.

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

2417  {
2418  if (NodeId==0){
2419  Clr();
2420  } else {
2421  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2422  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
2423  ChildNodeIdV[ChildNodeIdN]=-1;
2424  }
2425 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2378
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2349
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:2367

Here is the call graph for this function:

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

Definition at line 2405 of file ds.h.

References TRnd::GetUniDevInt().

2405  {
2406  Clr();
2407  if (Nodes>0){
2408  AddRoot(TVal());
2409  for (int NodeN=1; NodeN<Nodes; NodeN++){
2410  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
2411  AddNode(ParentNodeId, TVal());
2412  }
2413  }
2414 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2369
int GetNodes() const
Definition: ds.h:2376
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:2373
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
void Clr()
Definition: ds.h:2367

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

References TTree< TVal >::NodeV.

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

Definition at line 2379 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2365 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2392 of file ds.h.

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

2392  {
2393  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
2394  else if (GetParentNodeId(NodeId)==-1){return;}
2395  NodeIdV.Add(NodeId);
2396  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2397  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2398  if (ChildNodeId!=-1){
2399  GetNodeIdV(NodeIdV, ChildNodeId);
2400  }
2401  }
2402 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2378
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2380
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:2392
int GetNodes() const
Definition: ds.h:2376
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:2379
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 2376 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2381 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2378 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2362 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2363 of file ds.h.

References TTree< TVal >::NodeV.

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

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

Definition at line 2358 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2359 of file ds.h.

References TTree< TVal >::NodeV.

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

Definition at line 2354 of file ds.h.

References TTree< TVal >::NodeV.

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

2439  {
2440  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
2441  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
2442  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2443  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2444  if (ChildNodeId!=-1){
2445  WrTree(ChildNodeId, Lev+1);
2446  }
2447  }
2448 }
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2380
int GetChildren(const int &NodeId) const
Definition: ds.h:2379
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:2439

Member Data Documentation


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