mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Modernize Hash
ordering with C++20 <=>
Progress on #10832 This doesn't switch to auto-deriving the fields, but by defining `<=>` we allow deriving `<=>` in downstream types where `Hash` is used.
This commit is contained in:
parent
d16fcaee21
commit
cfc18a7739
2 changed files with 8 additions and 20 deletions
|
@ -50,21 +50,14 @@ bool Hash::operator == (const Hash & h2) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Hash::operator != (const Hash & h2) const
|
std::strong_ordering Hash::operator <=> (const Hash & h) const
|
||||||
{
|
{
|
||||||
return !(*this == h2);
|
if (auto cmp = algo <=> h.algo; cmp != 0) return cmp;
|
||||||
}
|
if (auto cmp = hashSize <=> h.hashSize; cmp != 0) return cmp;
|
||||||
|
|
||||||
|
|
||||||
bool Hash::operator < (const Hash & h) const
|
|
||||||
{
|
|
||||||
if (hashSize < h.hashSize) return true;
|
|
||||||
if (hashSize > h.hashSize) return false;
|
|
||||||
for (unsigned int i = 0; i < hashSize; i++) {
|
for (unsigned int i = 0; i < hashSize; i++) {
|
||||||
if (hash[i] < h.hash[i]) return true;
|
if (auto cmp = hash[i] <=> h.hash[i]; cmp != 0) return cmp;
|
||||||
if (hash[i] > h.hash[i]) return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
return std::strong_ordering::equivalent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -86,19 +86,14 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Check whether two hash are equal.
|
* Check whether two hashes are equal.
|
||||||
*/
|
*/
|
||||||
bool operator == (const Hash & h2) const;
|
bool operator == (const Hash & h2) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether two hash are not equal.
|
* Compare how two hashes are ordered.
|
||||||
*/
|
*/
|
||||||
bool operator != (const Hash & h2) const;
|
std::strong_ordering operator <=> (const Hash & h2) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* For sorting.
|
|
||||||
*/
|
|
||||||
bool operator < (const Hash & h) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of a base-16 representation of this hash.
|
* Returns the length of a base-16 representation of this hash.
|
||||||
|
|
Loading…
Reference in a new issue