00001 //---------------------------------------------------------------------------- 00002 /** @file Hash.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef HASH_HPP 00007 #define HASH_HPP 00008 00009 #include "SgSystem.h" 00010 #include "SgRandom.h" 00011 #include <sstream> 00012 #include <iomanip> 00013 00014 #include "Benzene.hpp" 00015 00016 _BEGIN_BENZENE_NAMESPACE_ 00017 00018 //---------------------------------------------------------------------------- 00019 00020 /** 64-bit hash value. */ 00021 typedef uint64_t hash_t; 00022 00023 //---------------------------------------------------------------------------- 00024 00025 /** Turn on hash collision detection. */ 00026 #define CHECK_HASH_COLLISION 0 00027 00028 //---------------------------------------------------------------------------- 00029 00030 /** Utilities on hash values. */ 00031 namespace HashUtil 00032 { 00033 /** Converts a hash value into a hex string. */ 00034 std::string toString(hash_t hash); 00035 00036 /** Returns a random hash value. */ 00037 hash_t RandomHash(); 00038 } 00039 00040 //---------------------------------------------------------------------------- 00041 00042 inline std::string HashUtil::toString(hash_t hash) 00043 { 00044 std::ostringstream os; 00045 os.fill('0'); 00046 os << "0x" << std::hex << std::setw(16) << hash; 00047 return os.str(); 00048 } 00049 00050 inline hash_t HashUtil::RandomHash() 00051 { 00052 hash_t a = SgRandom::Global().Int(); 00053 hash_t b = SgRandom::Global().Int(); 00054 a <<= 32; 00055 return a | b; 00056 } 00057 00058 //---------------------------------------------------------------------------- 00059 00060 _END_BENZENE_NAMESPACE_ 00061 00062 #endif // HASH_HPP