MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / retain_range

Function retain_range

crates/commitlog/src/stream/reader.rs:149–161  ·  view source on GitHub ↗

Given a list of (segment) offsets, retain those which fall into the `range`.

(offsets: &[u64], range: RangeFromMaybeToInclusive)

Source from the content-addressed store, hash-verified

147
148/// Given a list of (segment) offsets, retain those which fall into the `range`.
149pub fn retain_range(offsets: &[u64], range: RangeFromMaybeToInclusive) -> Vec<u64> {
150 if range.is_empty() {
151 return vec![];
152 }
153 offsets
154 .iter()
155 .zip(offsets.iter().skip(1).chain([&u64::MAX]))
156 .filter_map(|(&start, &end)| {
157 let in_start = range.start >= start && range.start < end;
158 (in_start || range.contains(&start)).then_some(start)
159 })
160 .collect()
161}
162
163#[cfg(test)]
164mod tests {

Calls 5

skipMethod · 0.80
iterMethod · 0.65
is_emptyMethod · 0.45
collectMethod · 0.45
containsMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…