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
|
#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 |
TInt & | operator= (const TInt &Int) |
TInt & | operator= (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 |
TInt & | operator+= (const int &Int) |
TInt & | operator-= (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 |
TInt::TInt | ( | ) | [inline] |
TInt::TInt | ( | const int & | _Val | ) | [inline] |
static int TInt::Abs | ( | const int & | Int | ) | [inline, static] |
static TStr TInt::GetHexStr | ( | const int & | Val | ) | [inline, static] |
static TStr TInt::GetHexStr | ( | const TInt & | Int | ) | [inline, static] |
static int TInt::GetInRng | ( | const int & | Val, |
const int & | Mn, | ||
const int & | Mx | ||
) | [inline, static] |
static TStr TInt::GetKiloStr | ( | const int & | Val | ) | [inline, static] |
static TStr TInt::GetMegaStr | ( | const int & | Val | ) | [inline, static] |
int TInt::GetMemUsed | ( | ) | const [inline] |
static int TInt::GetMn | ( | const int & | Int1, |
const int & | Int2 | ||
) | [inline, static] |
static int TInt::GetMn | ( | const int & | Int1, |
const int & | Int2, | ||
const int & | Int3 | ||
) | [inline, static] |
static int TInt::GetMn | ( | const int & | Int1, |
const int & | Int2, | ||
const int & | Int3, | ||
const int & | Int4 | ||
) | [inline, static] |
static int TInt::GetMx | ( | const int & | Int1, |
const int & | Int2 | ||
) | [inline, static] |
static int TInt::GetMx | ( | const int & | Int1, |
const int & | Int2, | ||
const int & | Int3 | ||
) | [inline, static] |
static int TInt::GetMx | ( | const int & | Int1, |
const int & | Int2, | ||
const int & | Int3, | ||
const int & | Int4 | ||
) | [inline, static] |
int TInt::GetPrimHashCd | ( | ) | const [inline] |
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] |
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] |
static TStr TInt::GetStr | ( | const TInt & | Int | ) | [inline, static] |
TStr TInt::GetStr | ( | const int & | Val, |
const char * | FmtStr | ||
) | [static] |
static TStr TInt::GetStr | ( | const int & | Val, |
const TStr & | FmtStr | ||
) | [inline, static] |
static TStr TInt::GetStr | ( | const uint & | Val | ) | [inline, static] |
static TStr TInt::GetStr | ( | const int64 & | Val | ) | [inline, static] |
static TStr TInt::GetStr | ( | const uint64 & | Val | ) | [inline, static] |
static bool TInt::IsEven | ( | const int & | Int | ) | [inline, static] |
static bool TInt::IsOdd | ( | const int & | Int | ) | [inline, static] |
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"); }
bool TInt::operator!= | ( | const int & | Int | ) | const [inline] |
TInt& TInt::operator+= | ( | const int & | Int | ) | [inline] |
TInt& TInt::operator-= | ( | const int & | Int | ) | [inline] |
bool TInt::operator< | ( | const TInt & | Int | ) | const [inline] |
bool TInt::operator< | ( | const int & | Int | ) | const [inline] |
TInt& TInt::operator= | ( | const int & | Int | ) | [inline] |
bool TInt::operator== | ( | const TInt & | Int | ) | const [inline] |
bool TInt::operator== | ( | const int & | Int | ) | const [inline] |
void TInt::Save | ( | TSOut & | SOut | ) | const [inline] |
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] |
static void TInt::Swap | ( | int & | Int1, |
int & | Int2 | ||
) | [inline, static] |
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 }
const int TInt::Giga = 1024*1024*1024 [static] |
const int TInt::Kilo = 1024 [static] |
const int TInt::Mega = 1024*1024 [static] |