Use comparator object for sorting StepRows

This commit is contained in:
Jack Grigg
2016-05-06 12:17:42 +12:00
parent a683cc85d9
commit 639c40047f
2 changed files with 26 additions and 8 deletions

View File

@@ -23,6 +23,8 @@ typedef uint8_t eh_trunc;
class StepRow
{
friend class CompareSR;
protected:
unsigned char* hash;
unsigned int len;
@@ -36,12 +38,20 @@ public:
bool IsZero();
std::string GetHex() { return HexStr(hash, hash+len); }
friend inline bool operator==(const StepRow& a, const StepRow& b) { return memcmp(a.hash, b.hash, a.len) == 0; }
friend inline bool operator<(const StepRow& a, const StepRow& b) { return memcmp(a.hash, b.hash, a.len) < 0; }
friend bool HasCollision(StepRow& a, StepRow& b, int l);
};
class CompareSR
{
private:
size_t len;
public:
CompareSR(size_t l) : len {l} { }
inline bool operator()(const StepRow& a, const StepRow& b) { return memcmp(a.hash, b.hash, len) < 0; }
};
bool HasCollision(StepRow& a, StepRow& b, int l);
class FullStepRow : public StepRow