Skip to content

Commit

Permalink
Merge branch 'main' into code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
jayz22 authored Sep 15, 2023
2 parents de9b15c + 6460cf6 commit 648e4eb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 66 deletions.
50 changes: 0 additions & 50 deletions soroban-env-host/src/host/metered_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,56 +260,6 @@ where
Ok(self.find(key, ctx)?.is_ok())
}

pub fn get_prev<Q>(&self, key: &Q, ctx: &Ctx) -> Result<Option<&(K, V)>, HostError>
where
K: Borrow<Q>,
Ctx: Compare<Q, Error = HostError>,
{
match self.find(key, ctx)? {
Ok(hit) if hit == 0 => Ok(None),
Ok(hit) => Ok(Some(&self.map[hit - 1])),
// Err(miss) means you could insert key at miss
// to maintain sort order (meaning that the element
// currently at miss, if it exists, is > than key).
Err(miss) if miss == 0 => Ok(None),
Err(miss) if miss - 1 < self.map.len() => Ok(Some(&self.map[miss - 1])),
Err(_) => Ok(None),
}
}

pub fn get_next<Q>(&self, key: &Q, ctx: &Ctx) -> Result<Option<&(K, V)>, HostError>
where
K: Borrow<Q>,
Ctx: Compare<Q, Error = HostError>,
{
match self.find(key, ctx)? {
Ok(hit) if (hit < usize::MAX) && (hit + 1 < self.map.len()) => {
Ok(Some(&self.map[hit + 1]))
}
Ok(hit) => Ok(None),
Err(miss) if (miss < self.map.len()) => Ok(Some(&self.map[miss])),
Err(miss) => Ok(None),
}
}

pub fn get_min<Q>(&self, ctx: &Ctx) -> Result<Option<&(K, V)>, HostError>
where
K: Borrow<Q>,
Ctx: Compare<Q, Error = HostError>,
{
self.charge_access(1, ctx)?;
Ok(self.map.as_slice().first())
}

pub fn get_max<Q>(&self, ctx: &Ctx) -> Result<Option<&(K, V)>, HostError>
where
K: Borrow<Q>,
Ctx: Compare<Q, Error = HostError>,
{
self.charge_access(1, ctx)?;
Ok(self.map.as_slice().last())
}

pub fn keys(&self, ctx: &Ctx) -> Result<impl Iterator<Item = &K>, HostError> {
self.charge_scan(ctx)?;
Ok(self.map.iter().map(|(k, _)| k))
Expand Down
16 changes: 0 additions & 16 deletions soroban-env-host/src/host/metered_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,6 @@ where
}
}

pub fn retain_mut<F>(&mut self, mut f: F, budget: &Budget) -> Result<Self, HostError>
where
F: FnMut(usize, &mut A) -> Result<bool, HostError>,
{
// The closure evaluation is not metered here, it is assumed to be taken care of outside.
// Here just covers the cost of cloning a Vec.
self.charge_deep_clone(budget)?;
let mut vec = Vec::with_capacity(self.len());
for (i, v) in self.vec.iter_mut().enumerate() {
if f(i, v)? {
vec.push(v.clone());
}
}
Self::from_vec(vec)
}

pub fn iter(&self) -> std::slice::Iter<'_, A> {
self.vec.iter()
}
Expand Down
4 changes: 4 additions & 0 deletions soroban-env-host/src/test/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ fn vec_insert_and_cmp() -> Result<(), HostError> {
let obj2 = host.vec_insert(obj1, 2u32.into(), 3u32.into())?;
let obj_ref = host.test_vec_obj::<u32>(&[1, 2, 3])?;
assert_eq!(host.obj_cmp(obj2.into(), obj_ref.into())?, 0);

let obj3 = host.vec_insert(obj2, 2u32.into(), 4u32.into())?;
let obj_ref = host.test_vec_obj::<u32>(&[1, 2, 4, 3])?;
assert_eq!(host.obj_cmp(obj3.into(), obj_ref.into())?, 0);
Ok(())
}

Expand Down

0 comments on commit 648e4eb

Please sign in to comment.