use super::{ROW_EMPTY_SLOT, RowMatchGenerator};
#[test]
fn rebasing_leaves_the_cursors_and_tags_alone() {
let mut matcher = RowMatchGenerator::new(1 << 20);
matcher.set_hash_bits(16);
matcher.ensure_tables();
let floor = 1_000usize;
for (i, slot) in matcher.row_positions_mut().iter_mut().enumerate() {
*slot = (floor + i) as u32;
}
matcher.row_heads_mut().fill(3);
matcher.row_tags_mut().fill(0x5A);
matcher.history_abs_start = floor;
matcher.rebase_positions();
assert!(
matcher.row_heads().iter().all(|&h| h == 3),
"the slot cursors are not positions and must survive the rebase"
);
assert!(
matcher.row_tags().iter().all(|&t| t == 0x5A),
"the hash tags are not positions and must survive the rebase"
);
assert_eq!(
matcher.row_positions()[0],
0,
"the first position sat exactly on the floor, so it rebases to zero"
);
assert_eq!(
matcher.row_positions()[1],
1,
"and the next one to one behind it"
);
}
#[test]
fn rebasing_a_chain_layout_still_walks_the_whole_buffer() {
let mut matcher = RowMatchGenerator::new(1 << 20);
matcher.set_hash_bits(16);
matcher.finder = super::LazyFinder::Chain;
matcher.ensure_tables();
assert_eq!(
matcher.row_positions().len(),
0,
"chain mode lays out no rows"
);
let floor = 500usize;
for slot in matcher.tables.iter_mut() {
*slot = floor as u32;
}
matcher.history_abs_start = floor;
matcher.rebase_positions();
assert!(
matcher
.tables
.iter()
.all(|&s| s == 0 || s == ROW_EMPTY_SLOT),
"every slot sat on the floor, so each rebases to zero"
);
}