Bachelors_Thesis_Code/processes.cpp
Knyffen c6b6329134 Abstrack simple string matching to a process
The process contains the fingerprinting function along with a queue
representing the sliding window. This means that the user no longer
needs to remember the outgoing character when streaming the text.
2021-11-14 16:19:11 +01:00

30 lines
758 B
C++

#include "processes.hpp"
Rabin_fingerprint_process::Rabin_fingerprint_process(uint32_t irr_poly, size_t window_size_in_bits)
: window_size_in_bits(window_size_in_bits),
phi(irr_poly, window_size_in_bits)
{}
void Rabin_fingerprint_process::stream_char (char c) {
std::bitset<8> b(c);
for (char i = 7; i >= 0; i--) {
stream_bit((bool)b[i]);
}
}
void Rabin_fingerprint_process::stream_bit (bool b) {
if (window.size() == window_size_in_bits) {
window.push(b);
bool b_out = window.front();
window.pop();
phi.slide_bit(b, b_out);
} else {
window.push(b);
phi.push_bit(b);
}
}
uint32_t Rabin_fingerprint_process::get_fingerprint () {
return phi.get_fingerprint();
}