Summary: - Removed durability::Summary because it was wired into reader and stopped me from recovering WAL files. - Refactored and renamed BufferedFile(Reader/Writer) to HashedFile(Reader/Writer). - Vertex and edge counts in the snapshot are now hashed. Breaking snapshot compatibility again (hashing), but since the previous version was not released, and we are not caching snapshots, the previous version does not need to be supported. Reviewers: teon.banek, mislav.bradac, buda Reviewed By: teon.banek, mislav.bradac Subscribers: dgleich, pullbot Differential Revision: https://phabricator.memgraph.io/D932
32 lines
654 B
C++
32 lines
654 B
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
|
|
// TODO: implement better hash function
|
|
|
|
/**
|
|
* Class calculates hash of the data dynamically.
|
|
*/
|
|
class Hasher {
|
|
/** Prime number used in calculating hash. */
|
|
static constexpr uint64_t kPrime = 3137;
|
|
|
|
public:
|
|
/**
|
|
* 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 (size_t i = 0; i < n; ++i) hash_ = hash_ * kPrime + data[i] + 1;
|
|
}
|
|
|
|
/** Returns current hash value. */
|
|
uint64_t hash() const { return hash_; }
|
|
|
|
private:
|
|
uint64_t hash_ = 0;
|
|
};
|