From d061fe55de758aafdec3b1ef378d83e0bee94242 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 27 Jul 2011 17:20:12 +0000 Subject: More features for uuids, including hashing and comparison. --- src/uuid.cpp | 15 +++++++++++++++ src/uuid.h | 12 ++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/uuid.cpp b/src/uuid.cpp index bcaf377..088450b 100644 --- a/src/uuid.cpp +++ b/src/uuid.cpp @@ -100,3 +100,18 @@ void Bu::Uuid::set( const Bu::String &sSrc ) } } +bool Bu::Uuid::operator==( const Uuid &rhs ) const +{ + return memcmp( data, rhs.data, 16 ) == 0; +} + +template<> uint32_t Bu::__calcHashCode( const Bu::Uuid &k ) +{ + return __calcHashCode( k.toRawString() ); +} + +template<> bool Bu::__cmpHashKeys( const Bu::Uuid &a, const Bu::Uuid &b ) +{ + return a == b; +} + diff --git a/src/uuid.h b/src/uuid.h index 1ffecc2..261f653 100644 --- a/src/uuid.h +++ b/src/uuid.h @@ -35,10 +35,22 @@ namespace Bu void clear(); + bool operator==( const Uuid &rhs ) const; + private: void set( const Bu::String &sSrc ); unsigned char data[16]; }; + + template + uint32_t __calcHashCode( const T &k ); + + template + bool __cmpHashKeys( const T &a, const T &b ); + + template<> uint32_t __calcHashCode( const Uuid &k ); + template<> bool __cmpHashKeys( + const Uuid &a, const Uuid &b ); }; #endif -- cgit v1.2.3