SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
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
bd.h
Go to the documentation of this file.
00001 #ifndef bd_h
00002 #define bd_h
00003 
00005 // Basic-Macro-Definitions
00006 #define forever for(;;)
00007 
00009 // Basic-Type-Definitions
00010 typedef unsigned char uchar;
00011 typedef unsigned int uint;
00012 typedef unsigned long ulong;
00013 typedef unsigned short ushort;
00014 
00015 typedef float sdouble;
00016 typedef long double ldouble;
00017 typedef FILE* TFileId;
00018 
00019 typedef char int8;
00020 typedef short int16;
00021 typedef int int32;
00022 #ifdef GLib_WIN32
00023 typedef __int64 int64;
00024 #elif defined(GLib_GLIBC)
00025 typedef int64_t int64;
00026 #else
00027 typedef long long int64;
00028 #endif
00029 
00030 typedef unsigned char uint8;
00031 typedef unsigned short uint16;
00032 typedef unsigned int uint32;
00033 #ifdef GLib_WIN32
00034 typedef unsigned __int64 uint64;
00035 #elif defined(GLib_GLIBC)
00036 typedef u_int64_t uint64;
00037 #else
00038 typedef unsigned long long uint64;
00039 #endif
00040 
00041 #if (!defined(__ssize_t_defined) && !defined(GLib_MACOSX))
00042 typedef ptrdiff_t ssize_t;
00043 #endif
00044 
00045 #if defined(GLib_UNIX)
00046 #define _isnan(x) isnan(x)
00047 #if defined(GLib_MACOSX)
00048   #define _finite(x) isfinite(x)
00049 #else
00050   #define _finite(x) finite(x)
00051 #endif
00052 #endif
00053 
00054 #if defined(GLib_WIN32)
00055 #define _vsnprintf vsnprintf
00056 #endif
00057 
00058 typedef size_t TSize;
00059 #define TSizeMx SIZE_MAX
00060 
00062 // Localization
00063 typedef enum {lUndef, lUs, lSi} TLoc;
00064 
00066 // Messages
00067 void WrNotify(const char* CaptionCStr, const char* NotifyCStr);
00068 void SaveToErrLog(const char* MsgCStr);
00069 
00070 inline void InfoNotify(const char* NotifyCStr){
00071   WrNotify("Information", NotifyCStr);}
00072 inline void WarnNotify(const char* NotifyCStr){
00073   WrNotify("Warning", NotifyCStr);}
00074 inline void ErrNotify(const char* NotifyCStr){
00075   WrNotify("Error", NotifyCStr);}
00076 inline void StatNotify(const char* NotifyCStr){
00077   WrNotify("Status", NotifyCStr);}
00078 
00080 // Compiler-Options
00081 #if defined (GLib_WIN)
00082   #define snprintf _snprintf
00083   #define vsnprintf  _vsnprintf
00084   // disable warning 'debug symbol greater than 255 chars'
00085   #pragma warning(disable: 4786)
00086   // disable warning 'return type for 'identifier::operator->'
00087   // is not a UDT or reference to a UDT.
00088   //#pragma warning(disable: 4284)
00089   // 'declaration' : function differs from 'declaration'
00090   // only by calling convention
00091   //#pragma warning(disable: 4666)
00092   #pragma warning(disable: 4996)
00093 #endif
00094 
00095 #if defined (GLib_GCC)
00096   #define _CONSOLE
00097 #endif
00098 
00099 // use console output if console already exists, otherwise
00100 // define GLib_COUT to use console (class COut)
00101 #if defined(_CONSOLE)||defined(__CONSOLE__)
00102   #define GLib_Console
00103 #endif
00104 
00105 // create console if want to output but there is no console allocated
00106 #if defined(GLib_Console) && (! (defined(__CONSOLE__)||defined(_CONSOLE)))
00107   #define GLib_CreateConsole
00108 #endif
00109 
00111 // Class-Definition
00112 #define ClassT(TNm) \
00113 class TNm{
00114 
00115 #define ClassTV(TNm, TNmV) \
00116 class TNm; \
00117 typedef TVec<TNm> TNmV; \
00118 class TNm{
00119 
00120 #define ClassTVQ(TNm, TNmV, TNmQ) \
00121 class TNm; \
00122 typedef TVec<TNm> TNmV; \
00123 typedef TQQueue<TNm> TNmQ; \
00124 class TNm{
00125 
00126 #define ClassTP(TNm, PNm) \
00127 class TNm; \
00128 typedef TPt<TNm> PNm; \
00129 class TNm{ \
00130 private: \
00131   TCRef CRef; \
00132 public: \
00133   friend class TPt<TNm>;
00134 
00135 #define ClassHdTP(TNm, PNm) \
00136 class TNm; \
00137 typedef TPt<TNm> PNm;
00138 
00139 #define ClassTPE(TNm, PNm, ENm) \
00140 class TNm; \
00141 typedef TPt<TNm> PNm; \
00142 class TNm: public ENm{ \
00143 private: \
00144   TCRef CRef; \
00145 public: \
00146   friend class TPt<TNm>;
00147 
00148 #define ClassTPEE(TNm, PNm, ENm1, ENm2) \
00149 class TNm; \
00150 typedef TPt<TNm> PNm; \
00151 class TNm: public ENm1, public ENm2{ \
00152 private: \
00153   TCRef CRef; \
00154 public: \
00155   friend class TPt<TNm>;
00156 
00157 #define ClassTE(TNm, ENm) \
00158 class TNm; \
00159 class TNm: public ENm{ \
00160 public: \
00161 
00162 #define ClassTPV(TNm, PNm, TNmV) \
00163 class TNm; \
00164 typedef TPt<TNm> PNm; \
00165 typedef TVec<PNm> TNmV; \
00166 class TNm{ \
00167 private: \
00168   TCRef CRef; \
00169 public: \
00170   friend class TPt<TNm>;
00171 
00172 #define ClassHdTPV(TNm, PNm, TNmV) \
00173 class TNm; \
00174 typedef TPt<TNm> PNm; \
00175 typedef TVec<PNm> TNmV;
00176 
00177 #define ClassTPVL(TNm, PNm, TNmV, TNmL, TNmLN) \
00178 class TNm; \
00179 typedef TPt<TNm> PNm; \
00180 typedef TVec<PNm> TNmV; \
00181 typedef TLst<PNm> TNmL; \
00182 typedef TLstNd<PNm>* TNmLN; \
00183 class TNm{ \
00184 private: \
00185   TCRef CRef; \
00186 public: \
00187   friend class TPt<TNm>;
00188 
00190 // Forward-Definitions
00191 class TSIn;
00192 class TSOut;
00193 class TStr;
00194 class TXmlObjSer;
00195 class TXmlObjSerTagNm;
00196 template <class TRec> class TPt;
00197 ClassHdTP(TXmlTok, PXmlTok)
00198 ClassHdTP(TExcept, PExcept)
00199 ClassHdTP(TXmlDoc, PXmlDoc)
00200 
00202 // DefaultConstructor/CopyConstructor/AssignmentOperator-UnDefinition
00203 #define UndefDefaultCopyAssign(TNm) \
00204 private: \
00205   TNm(){} \
00206   TNm(const TNm&); \
00207   TNm& operator=(const TNm&)
00208 
00209 #define UndefCopyAssign(TNm) \
00210 private: \
00211   TNm(const TNm&); \
00212   TNm& operator=(const TNm&)
00213 
00214 #define UndefCopy(TNm) \
00215 private: \
00216   TNm(const TNm&)
00217 
00218 #define UndefAssign(TNm) \
00219 private: \
00220   TNm& operator=(const TNm&)
00221 
00223 // Assertions
00224 class TOnExeStop{
00225 private:
00226   typedef bool (*TOnExeStopF)(char* MsgCStr);
00227   static TOnExeStopF OnExeStopF;
00228 public:
00229   static bool IsOnExeStopF(){return OnExeStopF!=NULL;}
00230   static void PutOnExeStopF(TOnExeStopF _OnExeStopF){OnExeStopF=_OnExeStopF;}
00231   static TOnExeStopF GetOnExeStopF(){return OnExeStopF;}
00232 };
00233 
00234 void ExeStop(
00235  const char* MsgStr, const char* ReasonStr,
00236  const char* CondStr, const char* FNm, const int& LnN);
00237 
00238 #define Fail ExeStop(NULL, NULL, "Fail", __FILE__, __LINE__)
00239 
00240 #define FailR(Reason) ExeStop((Reason), NULL, "Fail", __FILE__, __LINE__)
00241 #define FailRA(Reason, ArgStr) \
00242   ExeStop((TStr(Reason)+" ("+ArgStr+")").CStr(), NULL, "Fail", __FILE__, __LINE__)
00243 
00244 #define EFail TExcept::ThrowFull("", TStr("[")+ TStr(__FILE__) + " line " + TInt::GetStr(__LINE__) + "]")
00245 
00246 #define EFailR(Reason) TExcept::ThrowFull(Reason, TStr("[")+TStr(__FILE__)+" line "+TInt::GetStr(__LINE__)+"]")
00247 
00248 #ifdef NDEBUG
00249 #define Assert(Cond)
00250 #else
00251 #define Assert(Cond) \
00252   ((Cond) ? static_cast<void>(0) : ExeStop(NULL, NULL, #Cond, __FILE__, __LINE__))
00253 #endif
00254 
00255 #ifdef NDEBUG
00256 #define AssertR(Cond, Reason)
00257 #else
00258 #define AssertR(Cond, Reason) ((Cond) ? static_cast<void>(0) : \
00259   ExeStop(NULL, TStr(Reason).CStr(), #Cond, __FILE__, __LINE__))
00260 #endif
00261 
00262 #define IAssert(Cond) \
00263   ((Cond) ? static_cast<void>(0) : ExeStop(NULL, NULL, #Cond, __FILE__, __LINE__))
00264 
00265 #define IAssertR(Cond, Reason) \
00266   ((Cond) ? static_cast<void>(0) : ExeStop(NULL, TStr(Reason).CStr(), #Cond, __FILE__, __LINE__))
00267 
00268 #define WAssert(Cond, MsgCStr) \
00269   ((Cond) ? static_cast<void>(0) : WarnNotify(MsgCStr))
00270 
00271 #define SAssert(Cond) \
00272   ((Cond) ? static_cast<void>(0) : ExeStop(TSysStr::GetLastMsgCStr(), NULL, #Cond, __FILE__, __LINE__))
00273 
00274 #define FAssert(Cond, MsgCStr) \
00275   ((Cond) ? static_cast<void>(0) : ExeStop(TStr(MsgCStr).CStr(), NULL, NULL, __FILE__, __LINE__))
00276 
00277 #define FSAssert(Cond) \
00278   ((Cond) ? static_cast<void>(0) : ExeStop(TSysStr::GetLastMsgCStr(), NULL, NULL, __FILE__, __LINE__))
00279 
00280 #define EAssert(Cond) \
00281   ((Cond) ? static_cast<void>(0) : TExcept::ThrowFull(#Cond, TStr(__FILE__) + " line " + TInt::GetStr(__LINE__) +": "+ TStr(#Cond)))
00282 
00283 #define EAssertR(Cond, MsgStr) \
00284   ((Cond) ? static_cast<void>(0) : TExcept::ThrowFull(MsgStr, TStr(__FILE__)+" line "+TInt::GetStr(__LINE__)+": "+TStr(#Cond)))
00285 
00286 #define EAssertRA(Cond, MsgStr, ArgStr) \
00287   ((Cond) ? static_cast<void>(0) : TExcept::Throw(MsgStr, ArgStr))
00288 
00289 #define EAssertRAA(Cond, MsgStr, ArgStr1, ArgStr2) \
00290   ((Cond) ? static_cast<void>(0) : TExcept::Throw(MsgStr, ArgStr1, ArgStr2))
00291 
00292 #define ESAssert(Cond) \
00293   ((Cond) ? static_cast<void>(0) : TExcept::Throw(TSysStr::GetLastMsgCStr(), \
00294   TStr(__FILE__) + " line " + TInt::GetStr(__LINE__) +": "+ TStr(#Cond)))
00295 
00296 // compile time assert
00297 // #define STATIC_ASSERT(x) { const char temp[ (((x) == 0) ? 0 : 1) ] = {'\0'}; }
00298 template <bool BoolVal> struct TStaticAssert;
00299 template <> struct TStaticAssert<true> { enum { value = 1 }; };
00300 template<int IntVal> struct TStaticAssertTest{};
00301 
00302 #define CAssert(Cond) \
00303   /* typedef TStaticAssertTest<sizeof(TStaticAssert<(Cond)==0?false:true>)> TestStaticAssert; */
00304 
00306 // Xml-Object-Serialization
00307 template <class TRec>
00308 bool IsXLoadFromFileOk(const TStr& FNm, const TStr& Nm, TRec& Rec, TStr& MsgStr);
00309 template <class TRec>
00310 void XLoadFromFile(const TStr& FNm, const TStr& Nm, TRec& Rec);
00311 
00312 #define XLoadHd(Nm) \
00313   {TStr TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00314   TXmlObjSer::AssertXmlHd(XmlTok, Nm, TypeNm);}
00315 #define XLoad(Nm) \
00316   Nm.LoadXml(XmlTok->GetTagTok(#Nm), #Nm);
00317 
00318 #define XSaveHd(Nm) \
00319   TStr _TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00320   TXmlObjSerTagNm XmlObjSerTagNm(SOut, false, Nm, _TypeNm);
00321 #define XSaveHdArg(Nm, ArgNm, ArgVal) \
00322   TStr _TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00323   TXmlObjSerTagNm XmlObjSerTagNm(SOut, false, Nm, _TypeNm, ArgNm, ArgVal);
00324 #define XSaveBETag(Nm) \
00325   TStr _TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00326   TXmlObjSerTagNm XmlObjSerTagNm(SOut, true, Nm, _TypeNm);
00327 #define XSaveBETagArg(Nm, ArgNm, ArgVal) \
00328   TStr _TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00329   TXmlObjSerTagNm XmlObjSerTagNm(SOut, true, Nm, _TypeNm, ArgNm, ArgVal);
00330 #define XSaveBETagArg4(Nm, ArgNm1, ArgVal1, ArgNm2, ArgVal2, ArgNm3, ArgVal3, ArgNm4, ArgVal4) \
00331   TStr _TypeNm=TXmlObjSer::GetTagNm(TStr(typeid(*this).name())); \
00332   TXmlObjSerTagNm XmlObjSerTagNm(SOut, true, Nm, _TypeNm, ArgNm1, ArgVal1, ArgNm2, ArgVal2, ArgNm3, ArgVal3, ArgNm4, ArgVal4);
00333 #define XSave(Nm) \
00334   Nm.SaveXml(SOut, #Nm)
00335 #define XSaveToFile(Nm, FNm) \
00336   {TFOut SOut(FNm); Nm.SaveXml(SOut, #Nm);}
00337 
00339 // Basic-Operators
00340 typedef enum {loUndef, loNot, loAnd, loOr} TLogOp;
00341 typedef enum {roUndef, roLs, roLEq, roEq, roNEq, roGEq, roGt} TRelOp;
00342 
00344 // Comparation-Macros
00345 #ifndef min
00346   #define min(a,b) ((a)<(b)?(a):(b))
00347 #endif
00348 
00349 #ifndef max
00350   #define max(a,b) ((a)>(b)?(a):(b))
00351 #endif
00352 
00354 // Comparator-Definitions
00355 template<class T>
00356 class TEq{
00357 public:
00358   bool operator()(const T& x, const T& y) const {return x==y;}
00359 };
00360 
00361 template<class T>
00362 class TNEq{
00363 public:
00364   bool operator()(const T& x, const T& y) const {return x!=y;}
00365 };
00366 
00367 template<class T>
00368 class TLss{
00369 public:
00370   bool operator()(const T& x, const T& y) const {return x<y;}
00371   int Cmp(const T& d1, const T& d2) const {
00372     if (d1<d2){return -1;}
00373     else if (d2<d1){return 1;}
00374     else {return 0;}
00375   }
00376 };
00377 
00378 template<class T>
00379 class TLEq{
00380 public:
00381   bool operator()(const T& x, const T& y) const {return x<=y;}
00382 };
00383 
00384 template<class T>
00385 class TGtr{
00386 public:
00387   bool operator() (const T& x, const T& y) const { return x>y; }
00388   int Cmp(const T& d1, const T& d2) const { //** vprasaj Janeza za uporabo
00389     if (d1<d2){return 1;}
00390     else if (d2<d1){return -1;}
00391     else {return 0;}
00392   }
00393 };
00394 
00395 template<class T>
00396 class TGEq{
00397 public:
00398   bool operator()(const T& x, const T& y) const {return x>=y;}
00399 };
00400 
00401 template<class T>
00402 class TCmp{
00403 public:
00404   int operator()(const T& x, const T& y) const {
00405     if (x < y){return -1;}
00406     else if (x > y){return 1;}
00407     else {return 0;}
00408   }
00409 };
00410 
00412 // Operator-Definitions
00413 template <class TRec>
00414 bool operator!=(const TRec& Rec1, const TRec& Rec2){return !(Rec1==Rec2);}
00415 
00416 template <class TRec>
00417 bool operator>(const TRec& Rec1, const TRec& Rec2){return Rec2<Rec1;}
00418 
00419 template <class TRec>
00420 bool operator<=(const TRec& Rec1, const TRec& Rec2){return !(Rec2<Rec1);}
00421 
00422 template <class TRec>
00423 bool operator>=(const TRec& Rec1, const TRec& Rec2){return !(Rec1<Rec2);}
00424 
00425 template <class TRec>
00426 bool Cmp(const int& RelOp, const TRec& Rec1, const TRec& Rec2){
00427   switch (RelOp){
00428     case roLs: return Rec1<Rec2;
00429     case roLEq: return Rec1<=Rec2;
00430     case roEq: return Rec1==Rec2;
00431     case roNEq: return Rec1!=Rec2;
00432     case roGEq: return Rec1>=Rec2;
00433     case roGt: return Rec1>Rec2;
00434     default: Fail; return false;
00435   }
00436 }
00437 
00439 // Reference-Count
00440 class TCRef{
00441 private:
00442   int Refs;
00443 private:
00444   TCRef& operator=(const TCRef&);
00445   TCRef(const TCRef&);
00446 public:
00447   TCRef(): Refs(0){}
00448   ~TCRef(){Assert(Refs==0);}
00449 
00450   void MkRef(){Refs++;}
00451   void UnRef(){Assert(Refs>0); Refs--;}
00452   bool NoRef() const {return Refs==0;}
00453   int GetRefs() const {return Refs;}
00454 };
00455 
00457 // Smart-Pointer-With-Reference-Count
00458 template <class TRec>
00459 class TPt{
00460 public:
00461   typedef TRec TObj;
00462 private:
00463   TRec* Addr;
00464   void MkRef() const {
00465     if (Addr!=NULL){
00466       Addr->CRef.MkRef();
00467     }
00468   }
00469   void UnRef() const {
00470     if (Addr!=NULL){
00471       Addr->CRef.UnRef();
00472       if (Addr->CRef.NoRef()){delete Addr;}
00473     }
00474   }
00475 public:
00476   TPt(): Addr(NULL){}
00477   TPt(const TPt& Pt): Addr(Pt.Addr){MkRef();}
00478   TPt(TRec* _Addr): Addr(_Addr){MkRef();}
00479   static TPt New(){return TObj::New();}
00480   ~TPt(){UnRef();}
00481   explicit TPt(TSIn& SIn);
00482   explicit TPt(TSIn& SIn, void* ThisPt);
00483   void Save(TSOut& SOut) const;
00484   void LoadXml(const TPt<TXmlTok>& XmlTok, const TStr& Nm);
00485   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00486 
00487   TPt& operator=(const TPt& Pt){
00488     if (this!=&Pt){Pt.MkRef(); UnRef(); Addr=Pt.Addr;} return *this;}
00489   bool operator==(const TPt& Pt) const {return *Addr==*Pt.Addr;}
00490   bool operator!=(const TPt& Pt) const {return *Addr!=*Pt.Addr;}
00491   bool operator<(const TPt& Pt) const {return *Addr<*Pt.Addr;}
00492 
00493   TRec* operator->() const {Assert(Addr!=NULL); return Addr;}
00494   TRec& operator*() const {Assert(Addr!=NULL); return *Addr;}
00495   TRec& operator[](const int& RecN) const {
00496     Assert(Addr!=NULL); return Addr[RecN];}
00497   TRec* operator()() const {return Addr;}
00498   //const TRec* operator()() const {return Addr;}
00499   //TRec* operator()() {return Addr;}
00500 
00501   bool Empty() const { return Addr==NULL;}
00502   void Clr(){UnRef(); Addr=NULL;}
00503   int GetRefs() const {
00504     if (Addr==NULL){return -1;} else {return Addr->CRef.GetRefs();}}
00505 
00506   int GetPrimHashCd() const {return Addr->GetPrimHashCd();}
00507   int GetSecHashCd() const {return Addr->GetSecHashCd();}
00508 
00509   TPt<TRec> Clone(){return MkClone(*this);}
00510 };
00511 
00513 // Simple-String
00514 class TSStr{
00515 private:
00516   char* Bf;
00517 public:
00518   TSStr(): Bf(NULL){
00519     Bf=new char[0+1]; Bf[0]=0;}
00520   TSStr(const TSStr& SStr): Bf(NULL){
00521     Bf=new char[strlen(SStr.Bf)+1]; strcpy(Bf, SStr.Bf);}
00522   TSStr(const char* _Bf): Bf(NULL){
00523     Bf=new char[strlen(_Bf)+1]; strcpy(Bf, _Bf);}
00524   ~TSStr(){delete[] Bf;}
00525 
00526   TSStr& operator=(const TSStr& SStr){
00527     if (this!=&SStr){
00528       delete[] Bf; Bf=new char[strlen(SStr.Bf)+1]; strcpy(Bf, SStr.Bf);}
00529     return *this;}
00530 
00531   char* CStr() {return Bf;}
00532   const char* CStr() const {return Bf;}
00533   bool Empty() const {return Bf[0]==0;}
00534   int Len() const {return int(strlen(Bf));}
00535 };
00536 
00538 // Conversion-Pointer64-To-Integers32
00539 class TConv_Pt64Ints32{
00540 private:
00541   union{
00542     void* Pt;
00543     uint64 UInt64;
00544     struct {uint Ls; uint Ms;} UInt32;
00545   } Val;
00546   UndefCopyAssign(TConv_Pt64Ints32);
00547 public:
00548   TConv_Pt64Ints32(){
00549     Val.Pt=0; Val.UInt32.Ms=0; Val.UInt32.Ls=0;}
00550   TConv_Pt64Ints32(void* Pt){
00551     Val.UInt32.Ms=0; Val.UInt32.Ls=0; Val.Pt=Pt;}
00552   TConv_Pt64Ints32(const uint& Ms, const uint& Ls){
00553     Val.Pt=0; Val.UInt32.Ms=Ms; Val.UInt32.Ls=Ls;}
00554 
00555   void PutPt(void* Pt){Val.Pt=Pt;}
00556   void* GetPt() const {return Val.Pt;}
00557   void PutUInt64(const uint64& _UInt64){Val.UInt64=_UInt64;}
00558   uint64 GetUInt64() const {return Val.UInt64;}
00559   void PutMsUInt32(const uint& Ms){Val.UInt32.Ms=Ms;}
00560   uint GetMsUInt32() const {return Val.UInt32.Ms;}
00561   void PutLsUInt32(const uint& Ls){Val.UInt32.Ls=Ls;}
00562   uint GetLsUInt32() const {return Val.UInt32.Ls;}
00563 };
00564 
00566 // Swap
00567 template <class TRec>
00568 void Swap(TRec& Rec1, TRec& Rec2){
00569   TRec Rec=Rec1; Rec1=Rec2; Rec2=Rec;
00570 }
00571 
00573 
00575 
00577 class TPairHashImpl1 {
00578 public:
00579   static inline int GetHashCd(const int hc1, const int hc2) {
00580     unsigned long long sum = ((unsigned long long) hc1) + ((unsigned long long) hc2);
00581     unsigned long long c = ((sum * (sum + 1)) >> 1) + hc1;
00582     return (int) (c % 0x7fffffffULL); }
00583 };
00584 
00586 
00588 class TPairHashImpl2 {
00589 public:
00590   static inline int GetHashCd(const int hc1, const int hc2) {
00591     unsigned long long sum = ((unsigned long long) hc1) + ((unsigned long long) hc2);
00592     unsigned long long c = ((sum * (sum + 1)) >> 1) + hc1;
00593     unsigned int R = (unsigned int) (c >> 31), Q = (unsigned int) (c & 0x7fffffffULL);
00594     if ((R & 0x80000000U) != 0) R -= 0x7fffffffU;
00595     unsigned int RQ = R + Q;
00596     if (RQ < 0x7fffffffU) return (int) RQ;
00597     RQ -= 0x7fffffffU;
00598     return (RQ == 0x7fffffffU) ? 0 : (int) RQ; }
00599 };
00600 
00601 // Depending on the platform and compiler settings choose the faster implementation (of the same hash function)
00602 #if (defined(GLib_64Bit)) && ! (defined(DEBUG) || defined(_DEBUG))
00603   typedef TPairHashImpl1 TPairHashImpl;
00604 #else
00605   typedef TPairHashImpl2 TPairHashImpl;
00606 #endif
00607 
00608 
00609 #endif