SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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>

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

Constructor & Destructor Documentation

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

Definition at line 2399 of file ds.h.

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

Definition at line 2400 of file ds.h.

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

Definition at line 2401 of file ds.h.

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

Member Function Documentation

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

Definition at line 2417 of file ds.h.

2417  {
2418  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
2419  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
2420  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:2397
TVec< TInt > TIntV
Definition: ds.h:1529
template<class TVal >
int TTree< TVal >::AddRoot ( const TVal &  NodeVal = TVal())
inline

Definition at line 2421 of file ds.h.

2421  {
2422  return AddNode(-1, NodeVal);}
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2417
template<class TVal >
void TTree< TVal >::Clr ( )
inline

Definition at line 2415 of file ds.h.

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

Definition at line 2476 of file ds.h.

2476  {
2477  int DstNodeId=DstTree.AddNode(DstParentNodeId, GetNodeVal(SrcNodeId));
2478  for (int ChildN=0; ChildN<GetChildren(SrcNodeId); ChildN++){
2479  int ChildNodeId=GetChildNodeId(SrcNodeId, ChildN);
2480  if (ChildNodeId!=-1){
2481  CopyTree(ChildNodeId, DstTree, DstNodeId);
2482  }
2483  }
2484 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2417
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2428
void CopyTree(const int &SrcNodeId, TTree &DstTree, const int &DstParentNodeId=-1)
Definition: ds.h:2476
TVal & GetNodeVal(const int &NodeId)
Definition: ds.h:2429
int GetChildren(const int &NodeId) const
Definition: ds.h:2427
template<class TVal >
void TTree< TVal >::DelNode ( const int &  NodeId)

Definition at line 2465 of file ds.h.

2465  {
2466  if (NodeId==0){
2467  Clr();
2468  } else {
2469  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2470  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
2471  ChildNodeIdV[ChildNodeIdN]=-1;
2472  }
2473 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2426
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2397
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1487
void Clr()
Definition: ds.h:2415
template<class TVal >
void TTree< TVal >::GenRandomTree ( const int &  Nodes,
TRnd Rnd 
)

Definition at line 2453 of file ds.h.

2453  {
2454  Clr();
2455  if (Nodes>0){
2456  AddRoot(TVal());
2457  for (int NodeN=1; NodeN<Nodes; NodeN++){
2458  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
2459  AddNode(ParentNodeId, TVal());
2460  }
2461  }
2462 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2417
int GetNodes() const
Definition: ds.h:2424
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:2421
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
void Clr()
Definition: ds.h:2415
template<class TVal >
int TTree< TVal >::GetChildNodeId ( const int &  NodeId,
const int &  ChildN 
) const
inline

Definition at line 2428 of file ds.h.

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

Definition at line 2427 of file ds.h.

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

Definition at line 2413 of file ds.h.

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

Definition at line 2440 of file ds.h.

2440  {
2441  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
2442  else if (GetParentNodeId(NodeId)==-1){return;}
2443  NodeIdV.Add(NodeId);
2444  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2445  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2446  if (ChildNodeId!=-1){
2447  GetNodeIdV(NodeIdV, ChildNodeId);
2448  }
2449  }
2450 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2426
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2428
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:2440
int GetNodes() const
Definition: ds.h:2424
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
int GetChildren(const int &NodeId) const
Definition: ds.h:2427
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
template<class TVal >
int TTree< TVal >::GetNodes ( ) const
inline

Definition at line 2424 of file ds.h.

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

Definition at line 2429 of file ds.h.

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

Definition at line 2426 of file ds.h.

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

Definition at line 2410 of file ds.h.

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

Definition at line 2411 of file ds.h.

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

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

Definition at line 2406 of file ds.h.

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

Definition at line 2407 of file ds.h.

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

Definition at line 2402 of file ds.h.

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

2487  {
2488  for (int LevN=0; LevN<Lev; LevN++){printf("| ");}
2489  printf("%d (%d)\n", NodeId, GetChildren(NodeId));
2490  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2491  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2492  if (ChildNodeId!=-1){
2493  WrTree(ChildNodeId, Lev+1);
2494  }
2495  }
2496 }
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2428
int GetChildren(const int &NodeId) const
Definition: ds.h:2427
void WrTree(const int &NodeId=0, const int &Lev=0)
Definition: ds.h:2487

Member Data Documentation

template<class TVal >
TVec<TTriple<TInt, TIntV, TVal> > TTree< TVal >::NodeV
private

Definition at line 2397 of file ds.h.


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