Check for exact match

This commit is contained in:
Bojan Serafimov
2022-12-12 20:25:24 -05:00
parent d9a239475c
commit c11c19d568
2 changed files with 12 additions and 4 deletions

View File

@@ -55,8 +55,6 @@ impl<Value: Clone> PersistentLayerMap<Value> {
}
pub fn insert(self: &mut Self, key: Range<i128>, lsn: Range<u64>, value: Value) {
// TODO check for off-by-one errors
// It's only a persistent map, not a retroactive one
if let Some(last_entry) = self.historic.iter().rev().next() {
let last_lsn = last_entry.0;
@@ -112,8 +110,6 @@ impl<Value: Clone> PersistentLayerMap<Value> {
}
pub fn query(self: &Self, key: i128, lsn: u64) -> Option<Value> {
// TODO check for off-by-one errors
let version = self.historic.range(0..=lsn).rev().next()?.1;
version
.range(0..=key)

View File

@@ -272,6 +272,18 @@ impl LayerMap {
// might be better.
let latest_layer = self.index.query(key.to_i128(), end_lsn.0 - 1);
let latest_image = self.images.query(key.to_i128(), end_lsn.0 - 1);
// Check for exact match
if let Some(image) = &latest_image {
let img_lsn = image.get_lsn_range().start;
if Lsn(img_lsn.0 + 1) == end_lsn {
return Ok(Some(SearchResult {
layer: Arc::clone(&image),
lsn_floor: img_lsn,
}));
}
}
return Ok(latest_layer.map(|layer| {
// Compute lsn_floor
let mut lsn_floor = layer.get_lsn_range().start;