SNAP Library 2.2, User Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TInt Class Reference

#include <dt.h>

List of all members.

Public Member Functions

 TInt ()
 TInt (const int &_Val)
 operator int () const
 TInt (TSIn &SIn)
void Load (TSIn &SIn)
void Save (TSOut &SOut) const
void LoadXml (const PXmlTok &XmlTok, const TStr &Nm)
void SaveXml (TSOut &SOut, const TStr &Nm) const
TIntoperator= (const TInt &Int)
TIntoperator= (const int &Int)
bool operator== (const TInt &Int) const
bool operator== (const int &Int) const
bool operator!= (const int &Int) const
bool operator< (const TInt &Int) const
bool operator< (const int &Int) const
int operator() () const
TIntoperator+= (const int &Int)
TIntoperator-= (const int &Int)
TInt operator++ (int)
TInt operator-- (int)
int GetMemUsed () const
int GetPrimHashCd () const
int GetSecHashCd () const
TStr GetStr () const

Static Public Member Functions

static int Abs (const int &Int)
static int Sign (const int &Int)
static void Swap (int &Int1, int &Int2)
static int GetRnd (const int &Range=0)
static bool IsOdd (const int &Int)
static bool IsEven (const int &Int)
static int GetMn (const int &Int1, const int &Int2)
static int GetMx (const int &Int1, const int &Int2)
static int GetMn (const int &Int1, const int &Int2, const int &Int3)
static int GetMn (const int &Int1, const int &Int2, const int &Int3, const int &Int4)
static int GetMx (const int &Int1, const int &Int2, const int &Int3)
static int GetMx (const int &Int1, const int &Int2, const int &Int3, const int &Int4)
static int GetInRng (const int &Val, const int &Mn, const int &Mx)
static TStr GetStr (const int &Val)
static TStr GetStr (const TInt &Int)
static TStr GetStr (const int &Val, const char *FmtStr)
static TStr GetStr (const int &Val, const TStr &FmtStr)
static TStr GetStr (const uint &Val)
static TStr GetStr (const int64 &Val)
static TStr GetStr (const uint64 &Val)
static TStr GetHexStr (const int &Val)
static TStr GetHexStr (const TInt &Int)
static TStr GetKiloStr (const int &Val)
static TStr GetMegaStr (const int &Val)
static char * SaveFrugalInt (char *pDest, int i)
static char * LoadFrugalInt (char *pSrc, int &i)
static void TestFrugalInt ()
static void SaveFrugalIntV (TSOut &SOut, const TVec< TInt, int > &IntV)
static void LoadFrugalIntV (TSIn &SIn, TVec< TInt, int > &IntV, bool ClrP=true)

Public Attributes

int Val

Static Public Attributes

static const int Mn = INT_MIN
static const int Mx = INT_MAX
static const int Kilo = 1024
static const int Mega = 1024*1024
static const int Giga = 1024*1024*1024
static TRnd Rnd

Detailed Description

Definition at line 1041 of file dt.h.


Constructor & Destructor Documentation

TInt::TInt ( ) [inline]

Definition at line 1052 of file dt.h.

: Val(0){}
TInt::TInt ( const int &  _Val) [inline]

Definition at line 1053 of file dt.h.

: Val(_Val){}
TInt::TInt ( TSIn SIn) [inline, explicit]

Definition at line 1055 of file dt.h.

{SIn.Load(Val);}

Member Function Documentation

static int TInt::Abs ( const int &  Int) [inline, static]

Definition at line 1078 of file dt.h.

{return Int<0?-Int:Int;}
static TStr TInt::GetHexStr ( const int &  Val) [inline, static]

Definition at line 1121 of file dt.h.

                                       {
    char Bf[255]; sprintf(Bf, "%X", Val); return TStr(Bf);}
static TStr TInt::GetHexStr ( const TInt Int) [inline, static]

Definition at line 1123 of file dt.h.

                                        {
    return GetHexStr(Int.Val);}
static int TInt::GetInRng ( const int &  Val,
const int &  Mn,
const int &  Mx 
) [inline, static]

Definition at line 1101 of file dt.h.

                                                                   {
    IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}
static TStr TInt::GetKiloStr ( const int &  Val) [inline, static]

Definition at line 1126 of file dt.h.

                                        {
    if (Val>=100*1000){return GetStr(Val/1000)+"K";}
    else if (Val>=1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
    else {return GetStr(Val);}}
static TStr TInt::GetMegaStr ( const int &  Val) [inline, static]

Definition at line 1130 of file dt.h.

                                        {
    if (Val>=100*1000000){return GetStr(Val/1000000)+"M";}
    else if (Val>=1000000){
      return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
    else {return GetKiloStr(Val);}}
int TInt::GetMemUsed ( ) const [inline]

Definition at line 1073 of file dt.h.

{return sizeof(TInt);}
static int TInt::GetMn ( const int &  Int1,
const int &  Int2 
) [inline, static]

Definition at line 1087 of file dt.h.

                                                    {
    return Int1<Int2?Int1:Int2;}
static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3 
) [inline, static]

Definition at line 1091 of file dt.h.

                                                                     {
    return GetMn(Int1, GetMn(Int2, Int3));}
static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
) [inline, static]

Definition at line 1093 of file dt.h.

                                    {
    return GetMn(GetMn(Int1, Int2), GetMn(Int3, Int4));}
static int TInt::GetMx ( const int &  Int1,
const int &  Int2 
) [inline, static]

Definition at line 1089 of file dt.h.

                                                    {
    return Int1>Int2?Int1:Int2;}
static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3 
) [inline, static]

Definition at line 1096 of file dt.h.

                                                                     {
    return GetMx(Int1, GetMx(Int2, Int3));}
static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
) [inline, static]

Definition at line 1098 of file dt.h.

                                    {
    return GetMx(GetMx(Int1, Int2), GetMx(Int3, Int4));}
int TInt::GetPrimHashCd ( ) const [inline]

Definition at line 1075 of file dt.h.

{return Val;}
static int TInt::GetRnd ( const int &  Range = 0) [inline, static]

Definition at line 1082 of file dt.h.

{return Rnd.GetUniDevInt(Range);}
int TInt::GetSecHashCd ( ) const [inline]

Definition at line 1076 of file dt.h.

{return Val/0x10;}
TStr TInt::GetStr ( ) const [inline]

Definition at line 1104 of file dt.h.

{return TInt::GetStr(Val);}
static TStr TInt::GetStr ( const int &  Val) [inline, static]

Definition at line 1106 of file dt.h.

{ return TStr::Fmt("%d", Val); }
static TStr TInt::GetStr ( const TInt Int) [inline, static]

Definition at line 1107 of file dt.h.

{ return GetStr(Int.Val);}
TStr TInt::GetStr ( const int &  Val,
const char *  FmtStr 
) [static]

Definition at line 1932 of file dt.cpp.

                                                   {
  if (FmtStr==NULL){
    return GetStr(Val);
  } else {
    char Bf[255];
    sprintf(Bf, FmtStr, Val);
    return TStr(Bf);
  }
}
static TStr TInt::GetStr ( const int &  Val,
const TStr FmtStr 
) [inline, static]

Definition at line 1109 of file dt.h.

{ return GetStr(Val, FmtStr.CStr());}
static TStr TInt::GetStr ( const uint Val) [inline, static]

Definition at line 1112 of file dt.h.

{ return TStr::Fmt("%u", Val); }
static TStr TInt::GetStr ( const int64 Val) [inline, static]

Definition at line 1117 of file dt.h.

{return TStr::Fmt("%lld", Val);}
static TStr TInt::GetStr ( const uint64 Val) [inline, static]

Definition at line 1118 of file dt.h.

{return TStr::Fmt("%llu", Val);}
static bool TInt::IsEven ( const int &  Int) [inline, static]

Definition at line 1085 of file dt.h.

{return ((Int%2)==0);}
static bool TInt::IsOdd ( const int &  Int) [inline, static]

Definition at line 1084 of file dt.h.

{return ((Int%2)==1);}
void TInt::Load ( TSIn SIn) [inline]

Definition at line 1056 of file dt.h.

{SIn.Load(Val);}
char * TInt::LoadFrugalInt ( char *  pSrc,
int &  i 
) [static]

Definition at line 1975 of file dt.cpp.

                                           {
  i = 0;
  int ch = (int) ((unsigned char) (*pSrc++));
  if ((ch & 0x80) == 0) { i = ch; i--; return pSrc; }
  i = (ch & 0x7f);
  ch = (int) ((unsigned char) (*pSrc++));
  if ((ch & 0x80) == 0)
  {
    i |= (ch & 0x3f) << 7;
    if ((ch & 0x40) == 0) i += 128; else i = -1 - i;
    i--; return pSrc;
  }
  i |= (ch & 0x7f) << 7;
  ch = (int) ((unsigned char) (*pSrc++));
  i |= ch << 14;
  ch = (int) ((unsigned char) (*pSrc++));
  i |= (ch & 0x7f) << 22;
  if ((ch & 0x80) == 0) i += 128 + 8192; else i = (-1 - 8192) - i;
  i--; return pSrc;
}
void TInt::LoadFrugalIntV ( TSIn SIn,
TVec< TInt, int > &  IntV,
bool  ClrP = true 
) [static]

Definition at line 2043 of file dt.cpp.

                                                           {
  if (clearVec) v.Clr();
  char sizeBuf[4], *p, *pEnd;
  // Load the first frugally-stored integer into the sizeBuf
  // buffer.  'count' bytes will be read.
  sizeBuf[0] = SIn.GetCh(); int count = 1;
  if (sizeBuf[0] & 0x80)
  {
    sizeBuf[1] = SIn.GetCh(); count++;
    if (sizeBuf[1] & 0x80) { sizeBuf[2] = SIn.GetCh();
      sizeBuf[3] = SIn.GetCh(); count += 2;}
  }
  // Decode the stored size.
  int size;
  pEnd = LoadFrugalInt(&sizeBuf[0], size);
  IAssert(pEnd - &sizeBuf[0] == count);
  if (size <= 0) return;
  // Allocate a buffer and read the compressed data.
  char *buf = new char[size];
  SIn.GetBf(buf, size);
  // Decode the compressed integers and add them into 'v'.
  p = buf; pEnd = buf + size;
  while (p < pEnd)
    { int i; p = LoadFrugalInt(p, i); v.Add(i); }
  IAssert(p == pEnd);
  delete[] buf;
}
void TInt::LoadXml ( const PXmlTok XmlTok,
const TStr Nm 
)

Definition at line 1923 of file dt.cpp.

                                                       {
  XLoadHd(Nm);
  Val=TXmlObjSer::GetIntArg(XmlTok, "Val");
}
TInt::operator int ( ) const [inline]

Definition at line 1054 of file dt.h.

{return Val;}
bool TInt::operator!= ( const int &  Int) const [inline]

Definition at line 1065 of file dt.h.

{return Val!=Int;}
int TInt::operator() ( ) const [inline]

Definition at line 1068 of file dt.h.

{return Val;}
TInt TInt::operator++ ( int  ) [inline]

Definition at line 1071 of file dt.h.

{Val++; return *this;}
TInt& TInt::operator+= ( const int &  Int) [inline]

Definition at line 1069 of file dt.h.

{Val+=Int; return *this;}
TInt TInt::operator-- ( int  ) [inline]

Definition at line 1072 of file dt.h.

{Val--; return *this;}
TInt& TInt::operator-= ( const int &  Int) [inline]

Definition at line 1070 of file dt.h.

{Val-=Int; return *this;}
bool TInt::operator< ( const TInt Int) const [inline]

Definition at line 1066 of file dt.h.

{return Val<Int.Val;}
bool TInt::operator< ( const int &  Int) const [inline]

Definition at line 1067 of file dt.h.

{return Val<Int;}
TInt& TInt::operator= ( const TInt Int) [inline]

Definition at line 1061 of file dt.h.

{Val=Int.Val; return *this;}
TInt& TInt::operator= ( const int &  Int) [inline]

Definition at line 1062 of file dt.h.

{Val=Int; return *this;}
bool TInt::operator== ( const TInt Int) const [inline]

Definition at line 1063 of file dt.h.

{return Val==Int.Val;}
bool TInt::operator== ( const int &  Int) const [inline]

Definition at line 1064 of file dt.h.

{return Val==Int;}
void TInt::Save ( TSOut SOut) const [inline]

Definition at line 1057 of file dt.h.

{SOut.Save(Val);}
char * TInt::SaveFrugalInt ( char *  pDest,
int  i 
) [static]

Definition at line 1954 of file dt.cpp.

                                           {
  // <0xxx xxxx> has 128 combinations and is used to store -1..126.
  // <1xxx xxxx> <00xx xxxx> has 2^13 = 8192 combinations and is used to store 127..8318.
  // <1xxx xxxx> <01xx xxxx> has 2^13 = 8192 combinations and is used to store -2..-8193.
  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <0xxx xxxx> has 2^29 = 536870912 combinations and is used to store 8319..536879230.
  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <1xxx xxxx> has 2^29 = 536870912 combinations and is used to store -8194..-536879105.
  i++;
  if (i >= 0 && i <= 127) { *pDest++ = char(i); return pDest; }
  if (i >= 128 && i < 128 + 8192) { i -= 128; *pDest++ = char(0x80 | (i & 0x7f));
    *pDest++ = char((i >> 7) & 0x3f); return pDest; }
  if (i <= -1 && i > -1 - 8192) { i = -1 - i;  *pDest++ = char(0x80 | (i & 0x7f));
    *pDest++ = char(0x40 | ((i >> 7) & 0x3f)); return pDest; }
  if (i >= 128 + 8192 && i < 128 + 8192 + 536870912) { i -= 128 + 8192;
    *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
    *pDest++ = char((i >> 14) & 0xff); *pDest++ = char((i >> 22) & 0x7f); return pDest; }
  if (i <= -1 - 8192 && i > -1 - 8192 - 536870912) { i = (-1 - 8192) - i;
    *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
    *pDest++ = char((i >> 14) & 0xff); *pDest++ = char(0x80 | ((i >> 22) & 0x7f)); return pDest; }
  IAssertR(false, TInt::GetStr(i)); return 0;
}
void TInt::SaveFrugalIntV ( TSOut SOut,
const TVec< TInt, int > &  IntV 
) [static]

Definition at line 2018 of file dt.cpp.

                                                    {
  // Prepare a large enough buffer.
  int count = v.Len();
  char *buf = new char[4 * (count + 1)], *pStart, *pEnd;
  // Encode the contents of 'v'.
  pStart = buf + 4; pEnd = pStart;
  for (int i = 0; i < count; i++)
    pEnd = SaveFrugalInt(pEnd, v[i].Val);
  // Encode the size of the encoded contents of 'v'.
  // This is stored at the beginning of 'buf' and is then
  // moved so that there is no gap between it and the
  // beginning of the stored contents (at pStart).
  int size = int(pEnd - pStart);
  char *pSizeStart = buf;
  char *pSizeEnd = SaveFrugalInt(pSizeStart, size);
  while (pSizeEnd > pSizeStart) *(--pStart) = *(--pSizeEnd);
  // Write the buffer and free the memory.
  SOut.PutBf(pStart, TSize(pEnd - pStart));
  delete[] buf;
}
void TInt::SaveXml ( TSOut SOut,
const TStr Nm 
) const

Definition at line 1928 of file dt.cpp.

                                                    {
  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
}
static int TInt::Sign ( const int &  Int) [inline, static]

Definition at line 1079 of file dt.h.

{return Int<0?-1:(Int>0?1:0);}
static void TInt::Swap ( int &  Int1,
int &  Int2 
) [inline, static]

Definition at line 1080 of file dt.h.

                                        {
    int SwapInt1=Int1; Int1=Int2; Int2=SwapInt1;}
void TInt::TestFrugalInt ( ) [static]

Definition at line 1998 of file dt.cpp.

                        {
  char buf[10], *p = &buf[0], *r, *s;
  int i, j;
#define __TEST(from, to, len) \
  for (i = (from); i <= (to); i++) \
    { if ((i & 0xffff) == 0) printf("%d\r", i); \
      r = SaveFrugalInt(p, i); s = LoadFrugalInt(p, j); \
      IAssert(r == s); IAssert(i == j); IAssert(r - p == len); }

  __TEST(-1, 126, 1);
  __TEST(127, 127 + 8191, 2);
  __TEST(-2 - 8191, -2, 2);
  __TEST(127 + 8192, 127 + 8191 + (1 << 29), 4);
  __TEST(-2 - 8191 - (1 << 29), -2 - 8192, 4);
#undef __TEST
}

Member Data Documentation

const int TInt::Giga = 1024*1024*1024 [static]

Definition at line 1049 of file dt.h.

const int TInt::Kilo = 1024 [static]

Definition at line 1047 of file dt.h.

const int TInt::Mega = 1024*1024 [static]

Definition at line 1048 of file dt.h.

const int TInt::Mn = INT_MIN [static]

Definition at line 1045 of file dt.h.

const int TInt::Mx = INT_MAX [static]

Definition at line 1046 of file dt.h.

TRnd TInt::Rnd [static]

Definition at line 1050 of file dt.h.

int TInt::Val

Definition at line 1043 of file dt.h.


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