SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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 1137 of file dt.h.

Constructor & Destructor Documentation

TInt::TInt ( )
inline

Definition at line 1148 of file dt.h.

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

Definition at line 1149 of file dt.h.

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

Definition at line 1151 of file dt.h.

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

Member Function Documentation

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

Definition at line 1174 of file dt.h.

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

Definition at line 1217 of file dt.h.

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

Definition at line 1219 of file dt.h.

1219  {
1220  return GetHexStr(Int.Val);}
static TStr GetHexStr(const int &Val)
Definition: dt.h:1217
int Val
Definition: dt.h:1139
static int TInt::GetInRng ( const int &  Val,
const int &  Mn,
const int &  Mx 
)
inlinestatic

Definition at line 1197 of file dt.h.

1197  {
1198  IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}
#define IAssert(Cond)
Definition: bd.h:262
int Val
Definition: dt.h:1139
static const int Mx
Definition: dt.h:1142
static const int Mn
Definition: dt.h:1141
static TStr TInt::GetKiloStr ( const int &  Val)
inlinestatic

Definition at line 1222 of file dt.h.

1222  {
1223  if (Val>=100*1000){return GetStr(Val/1000)+"K";}
1224  else if (Val>=1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
1225  else {return GetStr(Val);}}
TStr GetStr() const
Definition: dt.h:1200
int Val
Definition: dt.h:1139
static TStr TInt::GetMegaStr ( const int &  Val)
inlinestatic

Definition at line 1226 of file dt.h.

1226  {
1227  if (Val>=100*1000000){return GetStr(Val/1000000)+"M";}
1228  else if (Val>=1000000){
1229  return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
1230  else {return GetKiloStr(Val);}}
TStr GetStr() const
Definition: dt.h:1200
int Val
Definition: dt.h:1139
static TStr GetKiloStr(const int &Val)
Definition: dt.h:1222
int TInt::GetMemUsed ( ) const
inline

Definition at line 1169 of file dt.h.

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

Definition at line 1183 of file dt.h.

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

Definition at line 1187 of file dt.h.

1187  {
1188  return GetMn(Int1, GetMn(Int2, Int3));}
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1183
static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
)
inlinestatic

Definition at line 1189 of file dt.h.

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

Definition at line 1185 of file dt.h.

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

Definition at line 1192 of file dt.h.

1192  {
1193  return GetMx(Int1, GetMx(Int2, Int3));}
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1185
static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3,
const int &  Int4 
)
inlinestatic

Definition at line 1194 of file dt.h.

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

Definition at line 1171 of file dt.h.

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

Definition at line 1178 of file dt.h.

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

Definition at line 1172 of file dt.h.

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

Definition at line 1200 of file dt.h.

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

Definition at line 1202 of file dt.h.

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

Definition at line 1203 of file dt.h.

1203 { return GetStr(Int.Val);}
TStr GetStr() const
Definition: dt.h:1200
int Val
Definition: dt.h:1139
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:1200
int Val
Definition: dt.h:1139
Definition: dt.h:412
static TStr TInt::GetStr ( const int &  Val,
const TStr FmtStr 
)
inlinestatic

Definition at line 1205 of file dt.h.

1205 { return GetStr(Val, FmtStr.CStr());}
TStr GetStr() const
Definition: dt.h:1200
int Val
Definition: dt.h:1139
char * CStr()
Definition: dt.h:479
static TStr TInt::GetStr ( const uint Val)
inlinestatic

Definition at line 1208 of file dt.h.

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

Definition at line 1213 of file dt.h.

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

Definition at line 1214 of file dt.h.

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

Definition at line 1181 of file dt.h.

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

Definition at line 1180 of file dt.h.

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

Definition at line 1152 of file dt.h.

1152 {SIn.Load(Val);}
int Val
Definition: dt.h:1139
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:1139
static int GetIntArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:74
TInt::operator int ( ) const
inline

Definition at line 1150 of file dt.h.

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

Definition at line 1161 of file dt.h.

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

Definition at line 1164 of file dt.h.

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

Definition at line 1167 of file dt.h.

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

Definition at line 1165 of file dt.h.

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

Definition at line 1168 of file dt.h.

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

Definition at line 1166 of file dt.h.

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

Definition at line 1162 of file dt.h.

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

Definition at line 1163 of file dt.h.

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

Definition at line 1157 of file dt.h.

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

Definition at line 1158 of file dt.h.

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

Definition at line 1159 of file dt.h.

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

Definition at line 1160 of file dt.h.

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

Definition at line 1153 of file dt.h.

1153 {SOut.Save(Val);}
int Val
Definition: dt.h:1139
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:1200
#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:1139
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:1200
#define XSaveBETagArg(Nm, ArgNm, ArgVal)
Definition: bd.h:327
int Val
Definition: dt.h:1139
static int TInt::Sign ( const int &  Int)
inlinestatic

Definition at line 1175 of file dt.h.

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

Definition at line 1176 of file dt.h.

1176  {
1177  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 1145 of file dt.h.

const int TInt::Kilo =1024
static

Definition at line 1143 of file dt.h.

const int TInt::Mega =1024*1024
static

Definition at line 1144 of file dt.h.

const int TInt::Mn =INT_MIN
static

Definition at line 1141 of file dt.h.

const int TInt::Mx =INT_MAX
static

Definition at line 1142 of file dt.h.

TRnd TInt::Rnd
static

Definition at line 1146 of file dt.h.

int TInt::Val

Definition at line 1139 of file dt.h.


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