utils: add a few VecMap utility functions

This commit is contained in:
Vlad Lazar
2024-02-15 17:50:58 +00:00
parent cffb5a66da
commit 4a9b29a8fc

View File

@@ -20,10 +20,22 @@ impl<K: Ord, V> VecMap<K, V> {
self.0.is_empty()
}
pub fn last(&self) -> Option<&(K, V)> {
self.0.last()
}
pub fn as_slice(&self) -> &[(K, V)] {
self.0.as_slice()
}
pub fn inner(self) -> Vec<(K, V)> {
self.0
}
pub fn len(&self) -> usize {
self.0.len()
}
/// This function may panic if given a range where the lower bound is
/// greater than the upper bound.
pub fn slice_range<R: RangeBounds<K>>(&self, range: R) -> &[(K, V)] {
@@ -90,6 +102,10 @@ impl<K: Ord, V> VecMap<K, V> {
Ok((None, delta_size))
}
pub fn truncate(&mut self, pos: usize) {
self.0.truncate(pos)
}
/// Split the map into two.
///
/// The left map contains everything before `cutoff` (exclusive).