SNAP Library 4.0, User Reference  2017-07-27 13:18:06
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 2460 of file ds.h.

Constructor & Destructor Documentation

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

Definition at line 2464 of file ds.h.

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

Definition at line 2465 of file ds.h.

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

Definition at line 2466 of file ds.h.

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

Member Function Documentation

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

Definition at line 2482 of file ds.h.

2482  {
2483  IAssert(((ParentNodeId==-1)&&(NodeV.Len()==0))||(NodeV.Len()>0));
2484  if (ParentNodeId!=-1){NodeV[ParentNodeId].Val2.Add(NodeV.Len());}
2485  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:2462
TVec< TInt > TIntV
Definition: ds.h:1594
template<class TVal >
int TTree< TVal >::AddRoot ( const TVal &  NodeVal = TVal())
inline

Definition at line 2486 of file ds.h.

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

Definition at line 2480 of file ds.h.

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

Definition at line 2541 of file ds.h.

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

Definition at line 2530 of file ds.h.

2530  {
2531  if (NodeId==0){
2532  Clr();
2533  } else {
2534  TIntV& ChildNodeIdV=NodeV[GetParentNodeId(NodeId)].Val2;
2535  int ChildNodeIdN=ChildNodeIdV.SearchForw(NodeId);
2536  ChildNodeIdV[ChildNodeIdN]=-1;
2537  }
2538 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2491
TVec< TTriple< TInt, TIntV, TVal > > NodeV
Definition: ds.h:2462
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:2480
template<class TVal >
void TTree< TVal >::GenRandomTree ( const int &  Nodes,
TRnd Rnd 
)

Definition at line 2518 of file ds.h.

2518  {
2519  Clr();
2520  if (Nodes>0){
2521  AddRoot(TVal());
2522  for (int NodeN=1; NodeN<Nodes; NodeN++){
2523  int ParentNodeId=Rnd.GetUniDevInt(0, GetNodes()-1);
2524  AddNode(ParentNodeId, TVal());
2525  }
2526  }
2527 }
int AddNode(const int &ParentNodeId, const TVal &NodeVal=TVal())
Definition: ds.h:2482
int GetNodes() const
Definition: ds.h:2489
int AddRoot(const TVal &NodeVal=TVal())
Definition: ds.h:2486
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
void Clr()
Definition: ds.h:2480
template<class TVal >
int TTree< TVal >::GetChildNodeId ( const int &  NodeId,
const int &  ChildN 
) const
inline

Definition at line 2493 of file ds.h.

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

Definition at line 2492 of file ds.h.

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

Definition at line 2478 of file ds.h.

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

Definition at line 2505 of file ds.h.

2505  {
2506  if (NodeId==0){NodeIdV.Clr(); if (GetNodes()==0){return;}}
2507  else if (GetParentNodeId(NodeId)==-1){return;}
2508  NodeIdV.Add(NodeId);
2509  for (int ChildN=0; ChildN<GetChildren(NodeId); ChildN++){
2510  int ChildNodeId=GetChildNodeId(NodeId, ChildN);
2511  if (ChildNodeId!=-1){
2512  GetNodeIdV(NodeIdV, ChildNodeId);
2513  }
2514  }
2515 }
int GetParentNodeId(const int &NodeId) const
Definition: ds.h:2491
int GetChildNodeId(const int &NodeId, const int &ChildN) const
Definition: ds.h:2493
void GetNodeIdV(TIntV &NodeIdV, const int &NodeId=0)
Definition: ds.h:2505
int GetNodes() const
Definition: ds.h:2489
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:2492
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
template<class TVal >
int TTree< TVal >::GetNodes ( ) const
inline

Definition at line 2489 of file ds.h.

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

Definition at line 2494 of file ds.h.

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

Definition at line 2491 of file ds.h.

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

Definition at line 2475 of file ds.h.

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

Definition at line 2476 of file ds.h.

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

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

Definition at line 2471 of file ds.h.

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

Definition at line 2472 of file ds.h.

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

Definition at line 2467 of file ds.h.

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

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

Member Data Documentation

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

Definition at line 2462 of file ds.h.


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