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

#include <bits.h>

Public Member Functions

 TBSet ()
 
 TBSet (const TBSet &BSet)
 
PBSet Clone () const
 
 TBSet (const int &_Bits)
 
 ~TBSet ()
 
 TBSet (TSIn &SIn)
 
void Save (TSOut &SOut) const
 
TBSetoperator= (const TBSet &BSet)
 
bool operator== (const TBSet &BSet) const
 
void Gen (const int &_Bits)
 
void Clr ()
 
void Fill ()
 
void Incl (const int &BitN)
 
void Excl (const int &BitN)
 
bool In (const int &BitN) const
 
void SetBit (const int &BitN, const bool &Bool)
 
bool GetBit (const int &BitN) const
 
void SwitchBit (const int &BitN)
 
int GetBits () const
 
int Get1s ()
 
int Get0s ()
 
uint64 GetUInt64 () const
 
void Wr ()
 
TBSetoperator~ ()
 
TBSetoperator&= (const TBSet &BSet)
 
TBSetoperator|= (const TBSet &BSet)
 
TBSetoperator|= (const int &BitN)
 
TBSetoperator^= (const TBSet &BSet)
 

Static Public Member Functions

static PBSet New (const int &Bits)
 
static PBSet Load (TSIn &SIn)
 

Private Member Functions

void SetLastB4 ()
 

Private Attributes

TCRef CRef
 
int B4s
 
int Bits
 
TB4Def::TB4 LastB4Mask
 
TB4Def::TB4B4T
 

Friends

class TPt< TBSet >
 
TBSet operator~ (const TBSet &BSet)
 
TBSet operator& (const TBSet &LBSet, const TBSet &RBSet)
 
TBSet operator| (const TBSet &LBSet, const TBSet &RBSet)
 
TBSet operator^ (const TBSet &LBSet, const TBSet &RBSet)
 
TBSet operator& (const TBSet &LBSet, const int &BitN)
 
TBSet operator| (const TBSet &LBSet, const int &BitN)
 
TBSet operator^ (const TBSet &LBSet, const int &BitN)
 

Detailed Description

Definition at line 313 of file bits.h.

Constructor & Destructor Documentation

TBSet::TBSet ( )
inline

Definition at line 320 of file bits.h.

320 : B4s(0), Bits(0), LastB4Mask(0), B4T(NULL){}
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet::TBSet ( const TBSet BSet)

Definition at line 163 of file bits.cpp.

163  :
164  B4s(0), Bits(0), LastB4Mask(0), B4T(NULL){
165  Gen(BSet.Bits);
166  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]=BSet.B4T[B4N];}
167 }
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
void Gen(const int &_Bits)
Definition: bits.cpp:182
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet::TBSet ( const int &  _Bits)
inline

Definition at line 323 of file bits.h.

323  :
324  B4s(0), Bits(0), LastB4Mask(0), B4T(NULL){Gen(_Bits);}
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
void Gen(const int &_Bits)
Definition: bits.cpp:182
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet::~TBSet ( )
inline

Definition at line 326 of file bits.h.

326 {delete[] B4T;}
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet::TBSet ( TSIn SIn)
inline

Definition at line 327 of file bits.h.

327  {
328  SIn.Load(B4s); SIn.Load(Bits);
329  SIn.LoadBf(&LastB4Mask, sizeof(TB4Def::TB4));
330  B4T=(TB4Def::TB4*)SIn.LoadNewBf(B4s*sizeof(TB4Def::TB4));}
void Load(bool &Bool)
Definition: fl.h:84
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
void * LoadNewBf(const int &BfL)
Definition: fl.h:82
int B4s
Definition: bits.h:315
void LoadBf(const void *Bf, const TSize &BfL)
Definition: fl.h:81
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
uint TB4
Definition: bits.h:53

Member Function Documentation

PBSet TBSet::Clone ( ) const
inline

Definition at line 322 of file bits.h.

322 {return PBSet(new TBSet(*this));}
TBSet()
Definition: bits.h:320
TPt< TBSet > PBSet
Definition: bits.h:313
void TBSet::Clr ( )

Definition at line 192 of file bits.cpp.

192  {
193  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]=0;}}
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
void TBSet::Excl ( const int &  BitN)
inline

Definition at line 348 of file bits.h.

348  {
349  Assert((0<=BitN)&&(BitN<Bits));
350  B4T[BitN/TB4Def::B4Def.B4Bits]&=
351  ~TB4Def::B4Def.B4P2T[BitN%TB4Def::B4Def.B4Bits];}
#define Assert(Cond)
Definition: bd.h:251
static const TB4Def B4Def
Definition: bits.h:68
Definition: bits.h:51
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
static const int B4Bits
Definition: bits.h:54
TB4 * B4P2T
Definition: bits.h:57
void TBSet::Fill ( )

Definition at line 195 of file bits.cpp.

195  {
196  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]=TB4Def::B4Def.MxB4;}}
static const TB4 MxB4
Definition: bits.h:56
static const TB4Def B4Def
Definition: bits.h:68
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
void TBSet::Gen ( const int &  _Bits)

Definition at line 182 of file bits.cpp.

182  {
183  if (B4T!=NULL){delete[] B4T;}
184  Bits=_Bits;
185  B4T=new TB4Def::TB4[B4s=(Bits-1)/TB4Def::B4Def.B4Bits+1];
187  for (int BitN=Bits; BitN<B4s*TB4Def::B4Def.B4Bits; BitN++){
188  LastB4Mask&= ~TB4Def::B4Def.B4P2T[BitN%TB4Def::B4Def.B4Bits];}
189  Clr();
190 }
void Clr()
Definition: bits.cpp:192
static const TB4 MxB4
Definition: bits.h:56
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
static const TB4Def B4Def
Definition: bits.h:68
int B4s
Definition: bits.h:315
Definition: bits.h:51
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
uint TB4
Definition: bits.h:53
static const int B4Bits
Definition: bits.h:54
TB4 * B4P2T
Definition: bits.h:57
int TBSet::Get0s ( )
inline

Definition at line 366 of file bits.h.

366 {return Bits-Get1s();}
int Get1s()
Definition: bits.cpp:198
int Bits
Definition: bits.h:315
int TBSet::Get1s ( )

Definition at line 198 of file bits.cpp.

198  {
199  int Ones=0; SetLastB4();
200  for (int B4N=0; B4N<B4s; B4N++){Ones += TB4Def::B4Def.GetB4Bits(B4T[B4N]);}
201  return Ones;
202 }
void SetLastB4()
Definition: bits.h:318
static int GetB4Bits(const TB4 &B4)
Definition: bits.cpp:83
static const TB4Def B4Def
Definition: bits.h:68
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
bool TBSet::GetBit ( const int &  BitN) const
inline

Definition at line 358 of file bits.h.

358  {
359  Assert((0<=BitN)&&(BitN<Bits));
360  return (B4T[BitN/TB4Def::B4Def.B4Bits] &
361  TB4Def::B4Def.B4P2T[BitN%TB4Def::B4Def.B4Bits])!=0;}
#define Assert(Cond)
Definition: bd.h:251
static const TB4Def B4Def
Definition: bits.h:68
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
int TBSet::GetBits ( ) const
inline

Definition at line 364 of file bits.h.

364 {return Bits;}
int Bits
Definition: bits.h:315
uint64 TBSet::GetUInt64 ( ) const
inline

Definition at line 367 of file bits.h.

367  {
368  Assert(Bits>=64); uint64 Val; memcpy(&Val, B4T, 8); return Val;}
unsigned long long uint64
Definition: bd.h:38
#define Assert(Cond)
Definition: bd.h:251
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
bool TBSet::In ( const int &  BitN) const
inline

Definition at line 352 of file bits.h.

352  {
353  Assert((0<=BitN)&&(BitN<Bits));
354  return (B4T[BitN/TB4Def::B4Def.B4Bits] &
355  TB4Def::B4Def.B4P2T[BitN%TB4Def::B4Def.B4Bits])!=0;}
#define Assert(Cond)
Definition: bd.h:251
static const TB4Def B4Def
Definition: bits.h:68
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
void TBSet::Incl ( const int &  BitN)
inline

Definition at line 344 of file bits.h.

344  {
345  Assert((0<=BitN)&&(BitN<Bits));
346  B4T[BitN/TB4Def::B4Def.B4Bits]|=
#define Assert(Cond)
Definition: bd.h:251
static const TB4Def B4Def
Definition: bits.h:68
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
static const int B4Bits
Definition: bits.h:54
TB4 * B4P2T
Definition: bits.h:57
static PBSet TBSet::Load ( TSIn SIn)
inlinestatic

Definition at line 331 of file bits.h.

331 {return new TBSet(SIn);}
TBSet()
Definition: bits.h:320
static PBSet TBSet::New ( const int &  Bits)
inlinestatic

Definition at line 325 of file bits.h.

325 {return PBSet(new TBSet(Bits));}
TBSet()
Definition: bits.h:320
TPt< TBSet > PBSet
Definition: bits.h:313
int Bits
Definition: bits.h:315
TBSet& TBSet::operator&= ( const TBSet BSet)
inline

Definition at line 373 of file bits.h.

373  {
374  Assert(B4s==BSet.B4s);
375  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]&=BSet.B4T[B4N];} return *this;}
#define Assert(Cond)
Definition: bd.h:251
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet & TBSet::operator= ( const TBSet BSet)

Definition at line 169 of file bits.cpp.

169  {
170  if (this!=&BSet){
171  if (Bits!=BSet.Bits){Gen(BSet.Bits);}
172  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]=BSet.B4T[B4N];}}
173  return *this;
174 }
void Gen(const int &_Bits)
Definition: bits.cpp:182
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
bool TBSet::operator== ( const TBSet BSet) const

Definition at line 176 of file bits.cpp.

176  {
177  if (Bits!=BSet.Bits){return false;}
178  for (int B4N=0; B4N<B4s-1; B4N++){if (B4T[B4N]!=BSet.B4T[B4N]){return false;}}
179  return (B4s>0)&&((B4T[B4s-1]&LastB4Mask)==(BSet.B4T[B4s-1]&BSet.LastB4Mask));
180 }
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet& TBSet::operator^= ( const TBSet BSet)
inline

Definition at line 381 of file bits.h.

381  {
382  Assert(B4s==BSet.B4s);
383  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]^=BSet.B4T[B4N];} return *this;}
#define Assert(Cond)
Definition: bd.h:251
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet& TBSet::operator|= ( const TBSet BSet)
inline

Definition at line 376 of file bits.h.

376  {
377  Assert(B4s==BSet.B4s);
378  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]|=BSet.B4T[B4N];} return *this;}
#define Assert(Cond)
Definition: bd.h:251
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
TBSet& TBSet::operator|= ( const int &  BitN)
inline

Definition at line 379 of file bits.h.

379  {
380  Incl(BitN); return *this;}
void Incl(const int &BitN)
Definition: bits.h:344
TBSet& TBSet::operator~ ( )
inline

Definition at line 371 of file bits.h.

371  {
372  for (int B4N=0; B4N<B4s; B4N++){B4T[B4N]=~B4T[B4N];} return *this;}
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
void TBSet::Save ( TSOut SOut) const
inline

Definition at line 332 of file bits.h.

332  {
333  SOut.Save(B4s); SOut.Save(Bits);
334  SOut.SaveBf(&LastB4Mask, sizeof(TB4Def::TB4));
335  SOut.SaveBf(B4T, B4s*sizeof(TB4Def::TB4));}
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
void SaveBf(const void *Bf, const TSize &BfL)
Definition: fl.h:172
void Save(const bool &Bool)
Definition: fl.h:173
int B4s
Definition: bits.h:315
int Bits
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
uint TB4
Definition: bits.h:53
void TBSet::SetBit ( const int &  BitN,
const bool &  Bool 
)
inline

Definition at line 356 of file bits.h.

356  {
357  if (Bool){Incl(BitN);} else {Excl(BitN);}}
void Excl(const int &BitN)
Definition: bits.h:348
void Incl(const int &BitN)
Definition: bits.h:344
void TBSet::SetLastB4 ( )
inlineprivate

Definition at line 318 of file bits.h.

318 {B4T[B4s-1]&=LastB4Mask;}
TB4Def::TB4 LastB4Mask
Definition: bits.h:316
int B4s
Definition: bits.h:315
TB4Def::TB4 * B4T
Definition: bits.h:317
void TBSet::SwitchBit ( const int &  BitN)
inline

Definition at line 362 of file bits.h.

362  {
363  SetBit(BitN, !GetBit(BitN));}
void SetBit(const int &BitN, const bool &Bool)
Definition: bits.h:356
bool GetBit(const int &BitN) const
Definition: bits.h:358
void TBSet::Wr ( )

Definition at line 204 of file bits.cpp.

204  {
205  for (int BitN=0; BitN<Bits; BitN++){printf("%d", GetBit(BitN));}
206  //printf("\n");
207 }
bool GetBit(const int &BitN) const
Definition: bits.h:358
int Bits
Definition: bits.h:315

Friends And Related Function Documentation

TBSet operator& ( const TBSet LBSet,
const TBSet RBSet 
)
friend

Definition at line 387 of file bits.h.

387  {
388  return TBSet(LBSet)&=RBSet;}
TBSet()
Definition: bits.h:320
TBSet operator& ( const TBSet LBSet,
const int &  BitN 
)
friend

Definition at line 394 of file bits.h.

394  {
395  return TBSet(LBSet)&=BitN;}
TBSet()
Definition: bits.h:320
TBSet operator^ ( const TBSet LBSet,
const TBSet RBSet 
)
friend

Definition at line 391 of file bits.h.

391  {
392  return TBSet(LBSet)^=RBSet;}
TBSet()
Definition: bits.h:320
TBSet operator^ ( const TBSet LBSet,
const int &  BitN 
)
friend

Definition at line 398 of file bits.h.

398  {
399  return TBSet(LBSet)^=BitN;}
TBSet()
Definition: bits.h:320
TBSet operator| ( const TBSet LBSet,
const TBSet RBSet 
)
friend

Definition at line 389 of file bits.h.

389  {
390  return TBSet(LBSet)|=RBSet;}
TBSet()
Definition: bits.h:320
TBSet operator| ( const TBSet LBSet,
const int &  BitN 
)
friend

Definition at line 396 of file bits.h.

396  {
397  return TBSet(LBSet)|=BitN;}
TBSet()
Definition: bits.h:320
TBSet operator~ ( const TBSet BSet)
friend

Definition at line 385 of file bits.h.

385  {
386  return ~TBSet(BSet);}
~TBSet()
Definition: bits.h:326
friend class TPt< TBSet >
friend

Definition at line 313 of file bits.h.

Member Data Documentation

int TBSet::B4s
private

Definition at line 315 of file bits.h.

TB4Def::TB4* TBSet::B4T
private

Definition at line 317 of file bits.h.

int TBSet::Bits
private

Definition at line 315 of file bits.h.

TCRef TBSet::CRef
private

Definition at line 313 of file bits.h.

TB4Def::TB4 TBSet::LastB4Mask
private

Definition at line 316 of file bits.h.


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