mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
proper cmake
This commit is contained in:
34
src/chunkers/srcs/Buzhash.cpp
Normal file
34
src/chunkers/srcs/Buzhash.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by Stepan Usatiuk on 26.04.2023.
|
||||
//
|
||||
|
||||
#include "../includes/Buzhash.h"
|
||||
|
||||
Buzhash::Buzhash(uint32_t blockSize) : blockSize(blockSize), history() {}
|
||||
|
||||
uint32_t Buzhash::get() const {
|
||||
return cur;
|
||||
}
|
||||
|
||||
uint32_t Buzhash::feed(uint8_t in) {
|
||||
cur = rotr32(cur, 1);
|
||||
|
||||
if (history.size() >= blockSize) {
|
||||
auto oldest = history.back();
|
||||
history.pop_back();
|
||||
cur ^= rotr32(randomNumbers[oldest], blockSize);
|
||||
}
|
||||
|
||||
history.emplace_front(in);
|
||||
|
||||
cur ^= randomNumbers[in];
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
// Circular shift taken from: https://en.wikipedia.org/wiki/Circular_shift
|
||||
uint32_t Buzhash::rotr32(uint32_t value, unsigned int count) {
|
||||
const unsigned int mask = CHAR_BIT * sizeof(value) - 1;
|
||||
count &= mask;
|
||||
return (value >> count) | (value << (-count & mask));
|
||||
}
|
||||
Reference in New Issue
Block a user