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
TComb Class Reference

#include <xmath.h>

Collaboration diagram for TComb:

Public Member Functions

 TComb ()
 
 TComb (const int &_Items, const int &_Order)
 
 ~TComb ()
 
 TComb (TSIn &)
 
void Save (TSOut &)
 
TComboperator= (const TComb &)
 
bool GetNext ()
 
TIntVGetItemV ()
 
int GetCombN () const
 
int GetCombs () const
 
void Wr ()
 

Static Public Member Functions

static PComb New (const int &Items, const int &Order)
 
static PComb Load (TSIn &SIn)
 

Public Attributes

int Items
 
int Order
 
int CombN
 
TIntV ItemV
 

Private Attributes

TCRef CRef
 

Friends

class TPt< TComb >
 

Detailed Description

Definition at line 316 of file xmath.h.

Constructor & Destructor Documentation

TComb::TComb ( )
inline

Definition at line 323 of file xmath.h.

323 : Items(-1), Order(-1), CombN(-1), ItemV(){}
int Order
Definition: xmath.h:319
int Items
Definition: xmath.h:318
int CombN
Definition: xmath.h:320
TIntV ItemV
Definition: xmath.h:321
TComb::TComb ( const int &  _Items,
const int &  _Order 
)
inline

Definition at line 324 of file xmath.h.

References IAssert.

324  :
325  Items(_Items), Order(_Order), CombN(0), ItemV(){
326  IAssert((Order>0)&&(Order<=Items));}
#define IAssert(Cond)
Definition: bd.h:262
int Order
Definition: xmath.h:319
int Items
Definition: xmath.h:318
int CombN
Definition: xmath.h:320
TIntV ItemV
Definition: xmath.h:321
TComb::~TComb ( )
inline

Definition at line 329 of file xmath.h.

329 {}
TComb::TComb ( TSIn )
inline

Definition at line 330 of file xmath.h.

References Fail.

330 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

int TComb::GetCombN ( ) const
inline

Definition at line 338 of file xmath.h.

Referenced by Wr().

338 {return CombN;}
int CombN
Definition: xmath.h:320

Here is the caller graph for this function:

int TComb::GetCombs ( ) const

Definition at line 759 of file xmath.cpp.

References Items, and Order.

759  {
760  int LCombs=1; int HCombs=1;
761  for (int OrderN=0; OrderN<Order; OrderN++){
762  LCombs*=OrderN+1; HCombs*=Items-OrderN;}
763  int Combs=HCombs/LCombs;
764  return Combs;
765 }
int Order
Definition: xmath.h:319
int Items
Definition: xmath.h:318
TIntV& TComb::GetItemV ( )
inline

Definition at line 337 of file xmath.h.

337 {return ItemV;}
TIntV ItemV
Definition: xmath.h:321
bool TComb::GetNext ( )

Definition at line 735 of file xmath.cpp.

References CombN, TVec< TVal, TSizeTy >::Gen(), Items, ItemV, TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::Len(), and Order.

735  {
736  if (ItemV.Len()==0){
737  ItemV.Gen(Order, Order);
738  for (int OrderN=0; OrderN<Order; OrderN++){
739  ItemV[OrderN]=OrderN;}
740  return true;
741  } else {
742  if (ItemV.Last()==Items-1){
743  int OrderN=Order-1;
744  while ((OrderN>=0)&&(ItemV[OrderN]==Items-(Order-OrderN-1)-1)){OrderN--;}
745  if (OrderN<0){
746  return false;
747  } else {
748  ItemV[OrderN]++;
749  for (int SubOrderN=OrderN+1; SubOrderN<Order; SubOrderN++){
750  ItemV[SubOrderN]=ItemV[SubOrderN-1]+1;}
751  CombN++; return true;
752  }
753  } else {
754  ItemV.Last()++; CombN++; return true;
755  }
756  }
757 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int Order
Definition: xmath.h:319
int Items
Definition: xmath.h:318
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:539
int CombN
Definition: xmath.h:320
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TIntV ItemV
Definition: xmath.h:321

Here is the call graph for this function:

static PComb TComb::Load ( TSIn SIn)
inlinestatic

Definition at line 331 of file xmath.h.

331 {return new TComb(SIn);}
TComb()
Definition: xmath.h:323
static PComb TComb::New ( const int &  Items,
const int &  Order 
)
inlinestatic

Definition at line 327 of file xmath.h.

327  {
328  return PComb(new TComb(Items, Order));}
int Order
Definition: xmath.h:319
TComb()
Definition: xmath.h:323
int Items
Definition: xmath.h:318
TPt< TComb > PComb
Definition: xmath.h:316
TComb& TComb::operator= ( const TComb )
inline

Definition at line 334 of file xmath.h.

References Fail.

334 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void TComb::Save ( TSOut )
inline

Definition at line 332 of file xmath.h.

References Fail.

332 {Fail;}
#define Fail
Definition: bd.h:238
void TComb::Wr ( )

Definition at line 767 of file xmath.cpp.

References GetCombN(), ItemV, and Order.

767  {
768  printf("%d:[", GetCombN());
769  for (int OrderN=0; OrderN<Order; OrderN++){
770  if (OrderN>0){printf(" ");}
771  printf("%d", ItemV[OrderN]());
772  }
773  printf("]\n");
774 }
int Order
Definition: xmath.h:319
int GetCombN() const
Definition: xmath.h:338
TIntV ItemV
Definition: xmath.h:321

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TPt< TComb >
friend

Definition at line 316 of file xmath.h.

Member Data Documentation

int TComb::CombN

Definition at line 320 of file xmath.h.

Referenced by GetNext().

TCRef TComb::CRef
private

Definition at line 316 of file xmath.h.

int TComb::Items

Definition at line 318 of file xmath.h.

Referenced by GetCombs(), and GetNext().

TIntV TComb::ItemV

Definition at line 321 of file xmath.h.

Referenced by GetNext(), and Wr().

int TComb::Order

Definition at line 319 of file xmath.h.

Referenced by GetCombs(), GetNext(), and Wr().


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