From 4a9b29a8fcd23d05332f20743009660b8c5b3248 Mon Sep 17 00:00:00 2001 From: Vlad Lazar Date: Thu, 15 Feb 2024 17:50:58 +0000 Subject: [PATCH] utils: add a few VecMap utility functions --- libs/utils/src/vec_map.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libs/utils/src/vec_map.rs b/libs/utils/src/vec_map.rs index 9953b447c8..66bc5d0c26 100644 --- a/libs/utils/src/vec_map.rs +++ b/libs/utils/src/vec_map.rs @@ -20,10 +20,22 @@ impl VecMap { 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>(&self, range: R) -> &[(K, V)] { @@ -90,6 +102,10 @@ impl VecMap { 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).