Add LayerMap::contains method

This commit is contained in:
Konstantin Knizhnik
2023-03-21 23:30:02 +02:00
parent 95dd5c71bf
commit 0cd01e33c3
2 changed files with 16 additions and 7 deletions

View File

@@ -122,6 +122,13 @@ impl<L> BatchedUpdates<'_, L>
where
L: ?Sized + Layer,
{
///
/// Check if layer map contains layers with specified key and LSN range
///
pub fn contains(&self, layer: Arc<L>) -> bool {
self.layer_map.contains(layer)
}
///
/// Insert an on-disk layer.
///
@@ -268,6 +275,14 @@ where
BatchedUpdates { layer_map: self }
}
///
/// Check if layer map contains layers with specified key and LSN range
///
pub fn contains(&self, layer: Arc<L>) -> bool {
self.historic
.contains(historic_layer_coverage::LayerKey::from(&*layer))
}
///
/// Insert an on-disk layer
///

View File

@@ -418,12 +418,6 @@ impl<Value: Clone> BufferedHistoricLayerCoverage<Value> {
}
pub fn insert(&mut self, layer_key: LayerKey, value: Value) {
// layer duplicates are not allowed
assert!(!self.layers.contains_key(&layer_key));
self.buffer.insert(layer_key, Some(value));
}
pub fn replace_existed(&mut self, layer_key: LayerKey, value: Value) {
self.buffer.insert(layer_key, Some(value));
}
@@ -478,7 +472,7 @@ impl<Value: Clone> BufferedHistoricLayerCoverage<Value> {
}
None => Replacement::NotFound,
Some(_existing) => {
self.replace_existed(layer_key.to_owned(), new);
self.insert(layer_key.to_owned(), new);
Replacement::Replaced { in_buffered }
}
}