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

#include <xmath.h>

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.

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.

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

Member Function Documentation

int TComb::GetCombN ( ) const
inline

Definition at line 338 of file xmath.h.

338 {return CombN;}
int CombN
Definition: xmath.h:320
int TComb::GetCombs ( ) const

Definition at line 759 of file xmath.cpp.

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.

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:547
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:551
int CombN
Definition: xmath.h:320
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TIntV ItemV
Definition: xmath.h:321
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.

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

Definition at line 332 of file xmath.h.

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

Definition at line 767 of file xmath.cpp.

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

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.

TCRef TComb::CRef
private

Definition at line 316 of file xmath.h.

int TComb::Items

Definition at line 318 of file xmath.h.

TIntV TComb::ItemV

Definition at line 321 of file xmath.h.

int TComb::Order

Definition at line 319 of file xmath.h.


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