Skip to content

Commit

Permalink
Remove metered map iterator functions. (stellar#1068)
Browse files Browse the repository at this point in the history
These aren't used/needed anymore.
  • Loading branch information
dmkozh authored Sep 14, 2023
1 parent 0d7b94e commit cf5c856
Showing 1 changed file with 0 additions and 50 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

0 comments on commit cf5c856

Please sign in to comment.