diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-08 17:53:10 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | c6c1b5217a48b60018bbd468b57cbcac600ec0ed (patch) | |
tree | c6ac9406b3a96e7bcc463b46b264e3a1e94c422d | |
parent | 31295f7da843f8e32f1dbdb7c3b552bb7e2f12b2 (diff) |
Add more comparison functions to hash
-rw-r--r-- | include/odhtdb/Hash.hpp | 3 | ||||
-rw-r--r-- | src/Hash.cpp | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/include/odhtdb/Hash.hpp b/include/odhtdb/Hash.hpp index c1212ec..05e85d2 100644 --- a/include/odhtdb/Hash.hpp +++ b/include/odhtdb/Hash.hpp @@ -38,6 +38,9 @@ namespace odhtdb size_t operator()() const; bool operator==(const Hash &other) const; + bool operator!=(const Hash &other) const; + + bool isEmpty() const; std::string toString() const; private: diff --git a/src/Hash.cpp b/src/Hash.cpp index 364cddd..4b045a4 100644 --- a/src/Hash.cpp +++ b/src/Hash.cpp @@ -17,6 +17,8 @@ namespace odhtdb static SodiumInitializer __sodiumInitializer; + static const Hash EMPTY_HASH; + Hash::Hash() { memset(data, 0, HASH_BYTE_SIZE); @@ -44,8 +46,18 @@ namespace odhtdb return memcmp(data, other.data, HASH_BYTE_SIZE) == 0; } + bool Hash::operator!=(const Hash &other) const + { + return !operator==(other); + } + std::string Hash::toString() const { return bin2hex(data, HASH_BYTE_SIZE); } + + bool Hash::isEmpty() const + { + return *this == EMPTY_HASH; + } } |