memgraph/src/durability/hasher.hpp
matej.gradicek 15b57e2d52 Implemented recovery and tests.
Summary: Implemented durability recovery and tesats.

Reviewers: mislav.bradac, dgleich, buda

Reviewed By: mislav.bradac, dgleich, buda

Subscribers: dtomicevic, mferencevic, pullbot

Differential Revision: https://phabricator.memgraph.io/D374
2017-06-06 15:12:34 +00:00

38 lines
719 B
C++

#pragma once
// TODO: implement better hash function
/**
* Class calculates hash of the data dynamically.
*/
class Hasher {
public:
Hasher() = default;
/**
* Sets hash to 0.
*/
void Reset() { hash_ = 0; }
/**
* Updates hash from given data.
* @param data data from which hash will be updated
* @param n length of the data
*/
void Update(const uint8_t *data, size_t n) {
for (int i = 0; i < n; ++i) hash_ = hash_ * kPrime + data[i] + 1;
}
/**
* Returns current hash value.
*/
uint64_t hash() const { return hash_; }
private:
/**
* Prime number used in calculating hash.
*/
const uint64_t kPrime = 3137;
/**
* Hash of data.
*/
uint64_t hash_ = 0;
};