Skip to content

Commit

Permalink
Now actually writing gap
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Aug 25, 2024
1 parent eb91be4 commit 28bec81
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/composite_hash/gaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,29 @@ where
// iter until we find where we should insert
let mut iter = GapHash::<CH>::downgraded(readable, number_of_hashes, hash_bits, 0);
let encoded = CH::encode(index, register, original_hash, hash_bits);
let mut gap = encoded;
let mut previous_value = u64::MAX;
for value in &mut iter {
if value <= encoded {
// The values are sorted in descending order, so we can stop when we find a value
// that is less than or equal to the value we want to insert
if encoded >= value {
// if the value is equal to the encoded value, we don't need to insert it
if value == encoded {
return false;
}
// We need to compute the gap between the value we want to insert and the previous value
if previous_value != u64::MAX {
gap = previous_value - encoded;
}
break;
}

previous_value = value;
}
// created a writer at the same position ! UNSAFE !
let mut writer = BitWriter::new(hashes_64);
writer.seek(iter.bitstream.tell());
let mut value_to_write = encoded;
let mut value_to_write = gap;
// keep reading and then writing the value
let iter_tell = unsafe{&*(&iter as *const _ as usize as *const <GapHash<CH> as CompositeHash>::Downgraded<'_>)};
for value in &mut iter {
Expand Down

0 comments on commit 28bec81

Please sign in to comment.