Refactor StepRow to make optimisation easier

This commit is contained in:
Jack Grigg
2016-04-16 01:14:37 +12:00
parent a09517f313
commit a3361e778b
3 changed files with 81 additions and 58 deletions

View File

@@ -22,38 +22,53 @@ struct invalid_params { };
class StepRow
{
private:
protected:
unsigned char* hash;
unsigned int len;
std::vector<eh_index> indices;
public:
StepRow(unsigned int n, const eh_HashState& base_state, eh_index i);
~StepRow();
StepRow(const StepRow& a);
StepRow& operator=(const StepRow& a);
StepRow& operator^=(const StepRow& a);
void TrimHash(int l);
bool IsZero();
bool IndicesBefore(const StepRow& a) { return indices[0] < a.indices[0]; }
std::vector<eh_index> GetSolution() { return std::vector<eh_index>(indices); }
std::string GetHex() { return HexStr(hash, hash+len); }
friend inline const StepRow operator^(const StepRow& a, const StepRow& b) {
if (a.indices[0] < b.indices[0]) { return StepRow(a) ^= b; }
else { return StepRow(b) ^= a; }
}
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);
friend bool DistinctIndices(const StepRow& a, const StepRow& b);
};
bool HasCollision(StepRow& a, StepRow& b, int l);
bool DistinctIndices(const StepRow& a, const StepRow& b);
class FullStepRow : public StepRow
{
private:
std::vector<eh_index> indices;
public:
FullStepRow(unsigned int n, const eh_HashState& base_state, eh_index i);
~FullStepRow() { }
FullStepRow(const FullStepRow& a) : StepRow {a}, indices(a.indices) { }
FullStepRow& operator=(const FullStepRow& a);
FullStepRow& operator^=(const FullStepRow& a);
void TrimHash(int l);
bool IndicesBefore(const FullStepRow& a) { return indices[0] < a.indices[0]; }
std::vector<eh_index> GetSolution() { return std::vector<eh_index>(indices); }
friend inline const FullStepRow operator^(const FullStepRow& a, const FullStepRow& b) {
if (a.indices[0] < b.indices[0]) { return FullStepRow(a) ^= b; }
else { return FullStepRow(b) ^= a; }
}
friend bool DistinctIndices(const FullStepRow& a, const FullStepRow& b);
};
bool DistinctIndices(const FullStepRow& a, const FullStepRow& b);
class Equihash
{