SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
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>

Collaboration diagram for TInt:

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.

Referenced by GetMemUsed().

: Val(0){}

Here is the caller graph for this function:

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.

References TSIn::Load(), and Val.

{SIn.Load(Val);}

Here is the call graph for this function:


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.

Referenced by GetHexStr(), and TUrl::GetUrlSearchStr().

                                       {
    char Bf[255]; sprintf(Bf, "%X", Val); return TStr(Bf);}

Here is the caller graph for this function:

static TStr TInt::GetHexStr ( const TInt Int) [inline, static]

Definition at line 1123 of file dt.h.

References GetHexStr(), and Val.

                                        {
    return GetHexStr(Int.Val);}

Here is the call graph for this function:

static int TInt::GetInRng ( const int &  Val,
const int &  Mn,
const int &  Mx 
) [inline, static]

Definition at line 1101 of file dt.h.

References IAssert, and Val.

Referenced by TVec< TVal, TSizeTy >::GetSubValV(), and TGLib_OLD::TVec< TVal >::GetSubValV().

                                                                   {
    IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}

Here is the caller graph for this function:

static TStr TInt::GetKiloStr ( const int &  Val) [inline, static]

Definition at line 1126 of file dt.h.

References GetStr().

Referenced by GetMegaStr().

                                        {
    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);}}

Here is the call graph for this function:

Here is the caller graph for this function:

static TStr TInt::GetMegaStr ( const int &  Val) [inline, static]

Definition at line 1130 of file dt.h.

References GetKiloStr(), and GetStr().

Referenced by TBigNet< TNodeData, IsDir >::InvertFromSources(), TBigNet< TNodeData, IsDir >::IsOk(), TLocClustStat::ParamStr(), TKroneckerLL::SampleGradient(), and TKroneckerLL::TestSamplePerm().

                                        {
    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);}}

Here is the call graph for this function:

Here is the caller graph for this function:

int TInt::GetMemUsed ( ) const [inline]

Definition at line 1073 of file dt.h.

References TInt().

{return sizeof(TInt);}

Here is the call graph for this function:

static int TInt::GetMn ( const int &  Int1,
const int &  Int2 
) [inline, static]

Definition at line 1087 of file dt.h.

Referenced by TVVec< TVal >::CopyFrom(), TStr::DelSubStr(), GetMn(), TMOut::GetSIn(), TChA::GetSubStr(), TStr::GetSubStr(), TQQueue< TInt >::GetSubValV(), TSparseSVD::Lanczos(), TSnap::PrintInfo(), TBigStrPool::Resize(), and TStrPool::Resize().

                                                    {
    return Int1<Int2?Int1:Int2;}

Here is the caller graph for this function:

static int TInt::GetMn ( const int &  Int1,
const int &  Int2,
const int &  Int3 
) [inline, static]

Definition at line 1091 of file dt.h.

References GetMn().

                                                                     {
    return GetMn(Int1, GetMn(Int2, Int3));}

Here is the call graph for this function:

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.

References GetMn().

                                    {
    return GetMn(GetMn(Int1, Int2), GetMn(Int3, Int4));}

Here is the call graph for this function:

static int TInt::GetMx ( const int &  Int1,
const int &  Int2,
const int &  Int3 
) [inline, static]

Definition at line 1096 of file dt.h.

References GetMx().

                                                                     {
    return GetMx(Int1, GetMx(Int2, Int3));}

Here is the call graph for this function:

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.

References GetMx().

                                    {
    return GetMx(GetMx(Int1, Int2), GetMx(Int3, Int4));}

Here is the call graph for this function:

int TInt::GetPrimHashCd ( ) const [inline]

Definition at line 1075 of file dt.h.

References Val.

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

Definition at line 1082 of file dt.h.

References TRnd::GetUniDevInt(), and Rnd.

Referenced by TVec< TVal, TSizeTy >::GetPivotValN(), TGLib_OLD::TVec< TVal >::GetPivotValN(), TVec< THKeyDat >::GetPivotValNCmp(), and TGLib_OLD::TVec< ::TSize >::GetPivotValNCmp().

{return Rnd.GetUniDevInt(Range);}

Here is the call graph for this function:

Here is the caller graph for this function:

int TInt::GetSecHashCd ( ) const [inline]

Definition at line 1076 of file dt.h.

References Val.

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

Definition at line 1106 of file dt.h.

References TStr::Fmt().

{ return TStr::Fmt("%d", Val); }

Here is the call graph for this function:

static TStr TInt::GetStr ( const TInt Int) [inline, static]

Definition at line 1107 of file dt.h.

References GetStr(), and Val.

Referenced by GetStr().

{ return GetStr(Int.Val);}

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TInt::GetStr ( const int &  Val,
const char *  FmtStr 
) [static]

Definition at line 1932 of file dt.cpp.

References GetStr().

                                                   {
  if (FmtStr==NULL){
    return GetStr(Val);
  } else {
    char Bf[255];
    sprintf(Bf, FmtStr, Val);
    return TStr(Bf);
  }
}

Here is the call graph for this function:

static TStr TInt::GetStr ( const int &  Val,
const TStr FmtStr 
) [inline, static]

Definition at line 1109 of file dt.h.

References TStr::CStr(), and GetStr().

Referenced by GetStr().

{ return GetStr(Val, FmtStr.CStr());}

Here is the call graph for this function:

Here is the caller graph for this function:

static TStr TInt::GetStr ( const uint Val) [inline, static]

Definition at line 1112 of file dt.h.

References TStr::Fmt().

{ return TStr::Fmt("%u", Val); }

Here is the call graph for this function:

static TStr TInt::GetStr ( const int64 Val) [inline, static]

Definition at line 1117 of file dt.h.

References TStr::Fmt().

{return TStr::Fmt("%lld", Val);}

Here is the call graph for this function:

static TStr TInt::GetStr ( const uint64 Val) [inline, static]

Definition at line 1118 of file dt.h.

References TStr::Fmt().

{return TStr::Fmt("%llu", Val);}

Here is the call graph for this function:

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);}
char * TInt::LoadFrugalInt ( char *  pSrc,
int &  i 
) [static]

Definition at line 1975 of file dt.cpp.

Referenced by LoadFrugalIntV().

                                           {
  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;
}

Here is the caller graph for this function:

void TInt::LoadFrugalIntV ( TSIn SIn,
TVec< TInt, int > &  IntV,
bool  ClrP = true 
) [static]

Definition at line 2043 of file dt.cpp.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), TSIn::GetBf(), TSIn::GetCh(), IAssert, and LoadFrugalInt().

                                                           {
  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;
}

Here is the call graph for this function:

void TInt::LoadXml ( const PXmlTok XmlTok,
const TStr Nm 
)

Definition at line 1923 of file dt.cpp.

References TXmlObjSer::GetIntArg(), Val, and XLoadHd.

                                                       {
  XLoadHd(Nm);
  Val=TXmlObjSer::GetIntArg(XmlTok, "Val");
}

Here is the call graph for this function:

TInt::operator int ( ) const [inline]

Definition at line 1054 of file dt.h.

References Val.

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

Definition at line 1065 of file dt.h.

References Val.

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

Definition at line 1068 of file dt.h.

References Val.

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

Definition at line 1071 of file dt.h.

References Val.

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

Definition at line 1069 of file dt.h.

References Val.

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

Definition at line 1072 of file dt.h.

References Val.

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

Definition at line 1070 of file dt.h.

References Val.

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

Definition at line 1066 of file dt.h.

References Val.

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

Definition at line 1067 of file dt.h.

References Val.

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

Definition at line 1061 of file dt.h.

References Val.

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

Definition at line 1062 of file dt.h.

References Val.

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

Definition at line 1063 of file dt.h.

References Val.

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

Definition at line 1064 of file dt.h.

References Val.

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

Definition at line 1057 of file dt.h.

References TSOut::Save(), and Val.

Referenced by TFHash< TKey, TFDat, TVDat >::AddDat(), TFHash< TKey, TFDat, TVDat >::AddKey(), TFHashKey< TKey, TFDat, TVDat >::OnDelFromCache(), THashKeyDat< TKey, TDat >::Save(), TGraphKey::Save(), TJsonVal::Save(), TNodeNet< TNodeData >::TNode::Save(), TAGMFit::Save(), TPpVal::Save(), TUNGraph::TNode::Save(), TAGMFast::Save(), THitInfo::Save(), TEdgeInfo::Save(), TCascade::Save(), TPp::Save(), TNodeInfo::Save(), THash< TIntPr, TEdgeInfo >::Save(), TSnapQueue< int >::Save(), TNodeNet< TSecTm >::Save(), TUNGraph::Save(), TGStatVec::Save(), TLocClustStat::Save(), TTm::Save(), TNGraph::TNode::Save(), TSparseTable< THashKeyDat, GroupSize >::Save(), TNGraph::Save(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::Save(), TSparseHash< TKey, TDat, GroupSize >::Save(), TNEGraph::TNode::Save(), TNEGraph::TEdge::Save(), TNodeEDatNet< TStr, TFltFltH >::Save(), TNEGraph::Save(), TStrHash< TDat, TStringPool, THashFunc >::Save(), TSparseSet< TKey, GroupSize >::Save(), TBPGraph::TNode::Save(), TBPGraph::Save(), THashSetKey< TKey >::Save(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::Save(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::Save(), THashSet< TInt >::Save(), TNodeEdgeNet< TSecTm, TSecTm >::Save(), TVVec< TFlt >::Save(), TVVVec< TVal >::Save(), TQQueue< TInt >::Save(), TBigNet< TNodeData, IsDir >::SaveToDisk(), and TFHash< TKey, TFDat, TVDat >::TFHash().

{SOut.Save(Val);}

Here is the call graph for this function:

Here is the caller graph for this function:

char * TInt::SaveFrugalInt ( char *  pDest,
int  i 
) [static]

Definition at line 1954 of file dt.cpp.

References GetStr(), and IAssertR.

Referenced by SaveFrugalIntV().

                                           {
  // <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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TInt::SaveFrugalIntV ( TSOut SOut,
const TVec< TInt, int > &  IntV 
) [static]

Definition at line 2018 of file dt.cpp.

References TVec< TVal, TSizeTy >::Len(), TSOut::PutBf(), SaveFrugalInt(), and Val.

                                                    {
  // 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;
}

Here is the call graph for this function:

void TInt::SaveXml ( TSOut SOut,
const TStr Nm 
) const

Definition at line 1928 of file dt.cpp.

References GetStr(), Val, and XSaveBETagArg.

                                                    {
  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
}

Here is the call graph for this function:

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.

References __TEST.

                        {
  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.

Referenced by TExpVal::GetFltValAsInt().


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