Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate cdc;
extern crate criterion;

use cdc::{Rabin64, RollingHash64};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};

pub fn slide_benchmarks(c: &mut Criterion) {
for i in [1_000, 10_000, 100_000] {
Expand All @@ -11,7 +11,7 @@ pub fn slide_benchmarks(c: &mut Criterion) {
b.iter(|| {
let mut rabin = Rabin64::new(5);
for _ in 0..i {
rabin.slide(&data)
rabin.slide(data)
}
})
});
Expand Down
12 changes: 6 additions & 6 deletions src/rolling_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub trait RollingHash64 {
fn reset_and_prefill_window<I>(&mut self, iter: &mut I) -> usize
where
I: Iterator<Item = u8>;
fn slide(&mut self, byte: &u8);
fn slide(&mut self, byte: u8);
fn get_hash(&self) -> &Polynom64;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ impl RollingHash64 for Rabin64 {
for _ in 0..self.window_size - 1 {
match iter.next() {
Some(b) => {
self.slide(&b);
self.slide(b);
nb_bytes_read += 1;
}
None => break,
Expand Down Expand Up @@ -154,16 +154,16 @@ impl RollingHash64 for Rabin64 {
}

#[inline]
fn slide(&mut self, byte: &u8) {
fn slide(&mut self, byte: u8) {
// Take the old value out of the window and the hash.
let out_value = self.window_data[self.window_index];
self.hash ^= self.out_table[out_value as usize];

// Put the new value in the window and in the hash.
self.window_data[self.window_index] = *byte;
self.window_data[self.window_index] = byte;
let mod_index = (self.hash >> self.polynom_shift) & 255;
self.hash <<= 8;
self.hash |= *byte as Polynom64;
self.hash |= byte as Polynom64;
self.hash ^= self.mod_table[mod_index as usize];

// Move the windowIndex to the next position.
Expand Down Expand Up @@ -216,7 +216,7 @@ mod tests {
rabin1.reset();
rabin1.hash_block(block, &MOD_POLYNOM);

rabin2.slide(&data[i]);
rabin2.slide(data[i]);

//println!("{:02} {:02} {:016x} {:016x} {:?}", i, block.len(), rabin1.hash, rabin2.hash, block);
assert_eq!(rabin1.hash, rabin2.hash);
Expand Down
2 changes: 1 addition & 1 deletion src/separator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
#[inline]
fn next(&mut self) -> Option<Self::Item> {
while let Some(byte) = self.iter.next() {
self.rabin.slide(&byte);
self.rabin.slide(byte);
self.index += 1;
if (self.predicate)(self.rabin.hash) {
let separator = Separator {
Expand Down