#include #include #include #include "ISHAHashValue.hxx" ClassImp(COMET::ISHAHashValue); COMET::ISHAHashValue::~ISHAHashValue() {} COMET::ISHAHashValue::ISHAHashValue() { for(int i=0; i<5; ++i) fHash[i] = 0; } COMET::ISHAHashValue::ISHAHashValue(const ISHAHashValue& hc) { for(int i=0; i<5; ++i) fHash[i] = hc(i); } COMET::ISHAHashValue::ISHAHashValue(unsigned int hc[5]) { for(int i=0; i<5; ++i) fHash[i] = hc[i]; } COMET::ISHAHashValue::ISHAHashValue(unsigned int hc0, unsigned int hc1, unsigned int hc2, unsigned int hc3, unsigned int hc4) { fHash[0] = hc0; fHash[1] = hc1; fHash[2] = hc2; fHash[3] = hc3; fHash[4] = hc4; } std::string COMET::ISHAHashValue::AsString() const { std::ostringstream nameStream; nameStream << std::hex << std::nouppercase << std::setfill('0'); if (fHash[0]) nameStream << std::setw(8) << fHash[0]; else nameStream << "xxxxxxxx"; nameStream << '-'; if (fHash[1]) nameStream << std::setw(8) << fHash[1]; else nameStream << "xxxxxxxx"; nameStream << '-'; if (fHash[2]) nameStream << std::setw(8) << fHash[2]; else nameStream << "xxxxxxxx"; nameStream << '-'; if (fHash[3]) nameStream << std::setw(8) << fHash[3]; else nameStream << "xxxxxxxx"; nameStream << '-'; if (fHash[4]) nameStream << std::setw(8) << fHash[4]; else nameStream << "xxxxxxxx"; return nameStream.str(); } bool COMET::ISHAHashValue::Equivalent(const ISHAHashValue& hc) const { bool valid = false; for (int i=0; i<5; ++i) { if (!fHash[i]) continue; if (!hc(i)) continue; if (hc(i)!=fHash[i]) return false; valid = true; } return valid; } bool COMET::ISHAHashValue::Valid() const { return (fHash[0] || fHash[1] || fHash[2] || fHash[3] || fHash[4]); } bool operator<(const COMET::ISHAHashValue& lhs, const COMET::ISHAHashValue& rhs) { for (int i=0; i<5; ++i) { if (lhs(i) > rhs(i)) return false; if (lhs(i) < rhs(i)) return true; } return false; } bool operator==(const COMET::ISHAHashValue& lhs, const COMET::ISHAHashValue& rhs) { for (int i=0; i<5; ++i) { if (lhs(i) != rhs(i)) return false; } return true; } std::ostream& operator<<(std::ostream& s, const COMET::ISHAHashValue& c) { s << "<"; s << c.AsString(); s << ">"; return s; }