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

#include <dt.h>

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 1044 of file dt.h.

Constructor & Destructor Documentation

TInt::TInt ( )
inline

Definition at line 1055 of file dt.h.

1055 : Val(0){}
int Val
Definition: dt.h:1046
TInt::TInt ( const int &  _Val)
inline

Definition at line 1056 of file dt.h.

1056 : Val(_Val){}
int Val
Definition: dt.h:1046
TInt::TInt ( TSIn SIn)
inlineexplicit

Definition at line 1058 of file dt.h.

1058 {SIn.Load(Val);}
int Val
Definition: dt.h:1046
void Load(bool &Bool)
Definition: fl.h:84

Member Function Documentation

static int TInt::Abs ( const int &  Int)
inlinestatic

Definition at line 1081 of file dt.h.

1081 {return Int<0?-Int:Int;}
static TStr TInt::GetHexStr ( const int &  Val)
inlinestatic

Definition at line 1124 of file dt.h.

1124  {
1125  char Bf[255]; sprintf(Bf, "%X", Val); return TStr(Bf);}
int Val
Definition: dt.h:1046
Definition: dt.h:412
static TStr TInt::GetHexStr ( const TInt Int)
inlinestatic

Definition at line 1126 of file dt.h.

1126  {
1127  return GetHexStr(Int.Val);}
static TStr GetHexStr(const int &Val)
Definition: dt.h:1124
int Val
Definition: dt.h:1046
static int TInt::GetInRng ( const int &  Val,
const int &  Mn,
const int &  Mx 
)
inlinestatic

Definition at line 1104 of file dt.h.

1104  {
1105  IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}
#define IAssert(Cond)
Definition: bd.h:262
int Val
Definition: dt.h:1046
static const int Mx
Definition: dt.h:1049
static const int Mn
Definition: dt.h:1048
static TStr TInt::GetKiloStr ( const int &  Val)
inlinestatic

Definition at line 1129 of file dt.h.

1129  {
1130  if (Val>=100*1000){return GetStr(Val/1000)+"K";}
1131  else if (Val>=1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
1132  else {return GetStr(Val);}}
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
static TStr TInt::GetMegaStr ( const int &  Val)
inlinestatic

Definition at line 1133 of file dt.h.

1133  {
1134  if (Val>=100*1000000){return GetStr(Val/1000000)+"M";}
1135  else if (Val>=1000000){
1136  return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
1137  else {return GetKiloStr(Val);}}
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
static TStr GetKiloStr(const int &Val)
Definition: dt.h:1129
int TInt::GetMemUsed ( ) const
inline

Definition at line 1076 of file dt.h.

1076 {return sizeof(TInt);}
TInt()
Definition: dt.h:1055
static int TInt::GetMn ( const int &  Int1,
const int &  Int2 
)
inlinestatic

Definition at line 1090 of file dt.h.

1090  {
1091  return Int1<Int2?Int1:Int2;}
static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3 
)
inlinestatic

Definition at line 1094 of file dt.h.

1094  {
1095  return GetMn(Int1, GetMn(Int2, Int3));}
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1090
static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
)
inlinestatic

Definition at line 1096 of file dt.h.

1097  {
1098  return GetMn(GetMn(Int1, Int2), GetMn(Int3, Int4));}
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1090
static int TInt::GetMx ( const int &  Int1,
const int &  Int2 
)
inlinestatic

Definition at line 1092 of file dt.h.

1092  {
1093  return Int1>Int2?Int1:Int2;}
static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3 
)
inlinestatic

Definition at line 1099 of file dt.h.

1099  {
1100  return GetMx(Int1, GetMx(Int2, Int3));}
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1092
static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
)
inlinestatic

Definition at line 1101 of file dt.h.

1102  {
1103  return GetMx(GetMx(Int1, Int2), GetMx(Int3, Int4));}
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1092
int TInt::GetPrimHashCd ( ) const
inline

Definition at line 1078 of file dt.h.

1078 {return Val;}
int Val
Definition: dt.h:1046
static int TInt::GetRnd ( const int &  Range = 0)
inlinestatic

Definition at line 1085 of file dt.h.

1085 {return Rnd.GetUniDevInt(Range);}
static TRnd Rnd
Definition: dt.h:1053
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
int TInt::GetSecHashCd ( ) const
inline

Definition at line 1079 of file dt.h.

1079 {return Val/0x10;}
int Val
Definition: dt.h:1046
TStr TInt::GetStr ( ) const
inline

Definition at line 1107 of file dt.h.

1107 {return TInt::GetStr(Val);}
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
static TStr TInt::GetStr ( const int &  Val)
inlinestatic

Definition at line 1109 of file dt.h.

1109 { return TStr::Fmt("%d", Val); }
int Val
Definition: dt.h:1046
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static TStr TInt::GetStr ( const TInt Int)
inlinestatic

Definition at line 1110 of file dt.h.

1110 { return GetStr(Int.Val);}
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
TStr TInt::GetStr ( const int &  Val,
const char *  FmtStr 
)
static

Definition at line 1932 of file dt.cpp.

1932  {
1933  if (FmtStr==NULL){
1934  return GetStr(Val);
1935  } else {
1936  char Bf[255];
1937  sprintf(Bf, FmtStr, Val);
1938  return TStr(Bf);
1939  }
1940 }
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
Definition: dt.h:412
static TStr TInt::GetStr ( const int &  Val,
const TStr FmtStr 
)
inlinestatic

Definition at line 1112 of file dt.h.

1112 { return GetStr(Val, FmtStr.CStr());}
TStr GetStr() const
Definition: dt.h:1107
int Val
Definition: dt.h:1046
char * CStr()
Definition: dt.h:476
static TStr TInt::GetStr ( const uint Val)
inlinestatic

Definition at line 1115 of file dt.h.

1115 { return TStr::Fmt("%u", Val); }
int Val
Definition: dt.h:1046
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static TStr TInt::GetStr ( const int64 Val)
inlinestatic

Definition at line 1120 of file dt.h.

1120 {return TStr::Fmt("%lld", Val);}
int Val
Definition: dt.h:1046
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static TStr TInt::GetStr ( const uint64 Val)
inlinestatic

Definition at line 1121 of file dt.h.

1121 {return TStr::Fmt("%llu", Val);}
int Val
Definition: dt.h:1046
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static bool TInt::IsEven ( const int &  Int)
inlinestatic

Definition at line 1088 of file dt.h.

1088 {return ((Int%2)==0);}
static bool TInt::IsOdd ( const int &  Int)
inlinestatic

Definition at line 1087 of file dt.h.

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

Definition at line 1059 of file dt.h.

1059 {SIn.Load(Val);}
int Val
Definition: dt.h:1046
void Load(bool &Bool)
Definition: fl.h:84
char * TInt::LoadFrugalInt ( char *  pSrc,
int &  i 
)
static

Definition at line 1975 of file dt.cpp.

1975  {
1976  i = 0;
1977  int ch = (int) ((unsigned char) (*pSrc++));
1978  if ((ch & 0x80) == 0) { i = ch; i--; return pSrc; }
1979  i = (ch & 0x7f);
1980  ch = (int) ((unsigned char) (*pSrc++));
1981  if ((ch & 0x80) == 0)
1982  {
1983  i |= (ch & 0x3f) << 7;
1984  if ((ch & 0x40) == 0) i += 128; else i = -1 - i;
1985  i--; return pSrc;
1986  }
1987  i |= (ch & 0x7f) << 7;
1988  ch = (int) ((unsigned char) (*pSrc++));
1989  i |= ch << 14;
1990  ch = (int) ((unsigned char) (*pSrc++));
1991  i |= (ch & 0x7f) << 22;
1992  if ((ch & 0x80) == 0) i += 128 + 8192; else i = (-1 - 8192) - i;
1993  i--; return pSrc;
1994 }
void TInt::LoadFrugalIntV ( TSIn SIn,
TVec< TInt, int > &  IntV,
bool  ClrP = true 
)
static

Definition at line 2043 of file dt.cpp.

2043  {
2044  if (clearVec) v.Clr();
2045  char sizeBuf[4], *p, *pEnd;
2046  // Load the first frugally-stored integer into the sizeBuf
2047  // buffer. 'count' bytes will be read.
2048  sizeBuf[0] = SIn.GetCh(); int count = 1;
2049  if (sizeBuf[0] & 0x80)
2050  {
2051  sizeBuf[1] = SIn.GetCh(); count++;
2052  if (sizeBuf[1] & 0x80) { sizeBuf[2] = SIn.GetCh();
2053  sizeBuf[3] = SIn.GetCh(); count += 2;}
2054  }
2055  // Decode the stored size.
2056  int size;
2057  pEnd = LoadFrugalInt(&sizeBuf[0], size);
2058  IAssert(pEnd - &sizeBuf[0] == count);
2059  if (size <= 0) return;
2060  // Allocate a buffer and read the compressed data.
2061  char *buf = new char[size];
2062  SIn.GetBf(buf, size);
2063  // Decode the compressed integers and add them into 'v'.
2064  p = buf; pEnd = buf + size;
2065  while (p < pEnd)
2066  { int i; p = LoadFrugalInt(p, i); v.Add(i); }
2067  IAssert(p == pEnd);
2068  delete[] buf;
2069 }
#define IAssert(Cond)
Definition: bd.h:262
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static char * LoadFrugalInt(char *pSrc, int &i)
Definition: dt.cpp:1975
virtual char GetCh()=0
void TInt::LoadXml ( const PXmlTok XmlTok,
const TStr Nm 
)

Definition at line 1923 of file dt.cpp.

1923  {
1924  XLoadHd(Nm);
1925  Val=TXmlObjSer::GetIntArg(XmlTok, "Val");
1926 }
#define XLoadHd(Nm)
Definition: bd.h:312
int Val
Definition: dt.h:1046
static int GetIntArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:74
TInt::operator int ( ) const
inline

Definition at line 1057 of file dt.h.

1057 {return Val;}
int Val
Definition: dt.h:1046
bool TInt::operator!= ( const int &  Int) const
inline

Definition at line 1068 of file dt.h.

1068 {return Val!=Int;}
int Val
Definition: dt.h:1046
int TInt::operator() ( ) const
inline

Definition at line 1071 of file dt.h.

1071 {return Val;}
int Val
Definition: dt.h:1046
TInt TInt::operator++ ( int  )
inline

Definition at line 1074 of file dt.h.

1074 {Val++; return *this;}
int Val
Definition: dt.h:1046
TInt& TInt::operator+= ( const int &  Int)
inline

Definition at line 1072 of file dt.h.

1072 {Val+=Int; return *this;}
int Val
Definition: dt.h:1046
TInt TInt::operator-- ( int  )
inline

Definition at line 1075 of file dt.h.

1075 {Val--; return *this;}
int Val
Definition: dt.h:1046
TInt& TInt::operator-= ( const int &  Int)
inline

Definition at line 1073 of file dt.h.

1073 {Val-=Int; return *this;}
int Val
Definition: dt.h:1046
bool TInt::operator< ( const TInt Int) const
inline

Definition at line 1069 of file dt.h.

1069 {return Val<Int.Val;}
int Val
Definition: dt.h:1046
bool TInt::operator< ( const int &  Int) const
inline

Definition at line 1070 of file dt.h.

1070 {return Val<Int;}
int Val
Definition: dt.h:1046
TInt& TInt::operator= ( const TInt Int)
inline

Definition at line 1064 of file dt.h.

1064 {Val=Int.Val; return *this;}
int Val
Definition: dt.h:1046
TInt& TInt::operator= ( const int &  Int)
inline

Definition at line 1065 of file dt.h.

1065 {Val=Int; return *this;}
int Val
Definition: dt.h:1046
bool TInt::operator== ( const TInt Int) const
inline

Definition at line 1066 of file dt.h.

1066 {return Val==Int.Val;}
int Val
Definition: dt.h:1046
bool TInt::operator== ( const int &  Int) const
inline

Definition at line 1067 of file dt.h.

1067 {return Val==Int;}
int Val
Definition: dt.h:1046
void TInt::Save ( TSOut SOut) const
inline

Definition at line 1060 of file dt.h.

1060 {SOut.Save(Val);}
int Val
Definition: dt.h:1046
void Save(const bool &Bool)
Definition: fl.h:173
char * TInt::SaveFrugalInt ( char *  pDest,
int  i 
)
static

Definition at line 1954 of file dt.cpp.

1954  {
1955  // <0xxx xxxx> has 128 combinations and is used to store -1..126.
1956  // <1xxx xxxx> <00xx xxxx> has 2^13 = 8192 combinations and is used to store 127..8318.
1957  // <1xxx xxxx> <01xx xxxx> has 2^13 = 8192 combinations and is used to store -2..-8193.
1958  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <0xxx xxxx> has 2^29 = 536870912 combinations and is used to store 8319..536879230.
1959  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <1xxx xxxx> has 2^29 = 536870912 combinations and is used to store -8194..-536879105.
1960  i++;
1961  if (i >= 0 && i <= 127) { *pDest++ = char(i); return pDest; }
1962  if (i >= 128 && i < 128 + 8192) { i -= 128; *pDest++ = char(0x80 | (i & 0x7f));
1963  *pDest++ = char((i >> 7) & 0x3f); return pDest; }
1964  if (i <= -1 && i > -1 - 8192) { i = -1 - i; *pDest++ = char(0x80 | (i & 0x7f));
1965  *pDest++ = char(0x40 | ((i >> 7) & 0x3f)); return pDest; }
1966  if (i >= 128 + 8192 && i < 128 + 8192 + 536870912) { i -= 128 + 8192;
1967  *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1968  *pDest++ = char((i >> 14) & 0xff); *pDest++ = char((i >> 22) & 0x7f); return pDest; }
1969  if (i <= -1 - 8192 && i > -1 - 8192 - 536870912) { i = (-1 - 8192) - i;
1970  *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1971  *pDest++ = char((i >> 14) & 0xff); *pDest++ = char(0x80 | ((i >> 22) & 0x7f)); return pDest; }
1972  IAssertR(false, TInt::GetStr(i)); return 0;
1973 }
TStr GetStr() const
Definition: dt.h:1107
#define IAssertR(Cond, Reason)
Definition: bd.h:265
void TInt::SaveFrugalIntV ( TSOut SOut,
const TVec< TInt, int > &  IntV 
)
static

Definition at line 2018 of file dt.cpp.

2018  {
2019  // Prepare a large enough buffer.
2020  int count = v.Len();
2021  char *buf = new char[4 * (count + 1)], *pStart, *pEnd;
2022  // Encode the contents of 'v'.
2023  pStart = buf + 4; pEnd = pStart;
2024  for (int i = 0; i < count; i++)
2025  pEnd = SaveFrugalInt(pEnd, v[i].Val);
2026  // Encode the size of the encoded contents of 'v'.
2027  // This is stored at the beginning of 'buf' and is then
2028  // moved so that there is no gap between it and the
2029  // beginning of the stored contents (at pStart).
2030  int size = int(pEnd - pStart);
2031  char *pSizeStart = buf;
2032  char *pSizeEnd = SaveFrugalInt(pSizeStart, size);
2033  while (pSizeEnd > pSizeStart) *(--pStart) = *(--pSizeEnd);
2034  // Write the buffer and free the memory.
2035  SOut.PutBf(pStart, TSize(pEnd - pStart));
2036  delete[] buf;
2037 }
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
int Val
Definition: dt.h:1046
static char * SaveFrugalInt(char *pDest, int i)
Definition: dt.cpp:1954
size_t TSize
Definition: bd.h:58
void TInt::SaveXml ( TSOut SOut,
const TStr Nm 
) const

Definition at line 1928 of file dt.cpp.

1928  {
1929  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
1930 }
TStr GetStr() const
Definition: dt.h:1107
#define XSaveBETagArg(Nm, ArgNm, ArgVal)
Definition: bd.h:327
int Val
Definition: dt.h:1046
static int TInt::Sign ( const int &  Int)
inlinestatic

Definition at line 1082 of file dt.h.

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

Definition at line 1083 of file dt.h.

1083  {
1084  int SwapInt1=Int1; Int1=Int2; Int2=SwapInt1;}
void TInt::TestFrugalInt ( )
static

Definition at line 1998 of file dt.cpp.

1998  {
1999  char buf[10], *p = &buf[0], *r, *s;
2000  int i, j;
2001 #define __TEST(from, to, len) \
2002  for (i = (from); i <= (to); i++) \
2003  { if ((i & 0xffff) == 0) printf("%d\r", i); \
2004  r = SaveFrugalInt(p, i); s = LoadFrugalInt(p, j); \
2005  IAssert(r == s); IAssert(i == j); IAssert(r - p == len); }
2006 
2007  __TEST(-1, 126, 1);
2008  __TEST(127, 127 + 8191, 2);
2009  __TEST(-2 - 8191, -2, 2);
2010  __TEST(127 + 8192, 127 + 8191 + (1 << 29), 4);
2011  __TEST(-2 - 8191 - (1 << 29), -2 - 8192, 4);
2012 #undef __TEST
2013 }
#define __TEST(from, to, len)

Member Data Documentation

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

Definition at line 1052 of file dt.h.

const int TInt::Kilo =1024
static

Definition at line 1050 of file dt.h.

const int TInt::Mega =1024*1024
static

Definition at line 1051 of file dt.h.

const int TInt::Mn =INT_MIN
static

Definition at line 1048 of file dt.h.

const int TInt::Mx =INT_MAX
static

Definition at line 1049 of file dt.h.

TRnd TInt::Rnd
static

Definition at line 1053 of file dt.h.

int TInt::Val

Definition at line 1046 of file dt.h.


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