MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / lookup_prefix

Method lookup_prefix

nodedb/src/engine/kv/index.rs:206–218  ·  view source on GitHub ↗

Prefix lookup: match on leading fields only. E.g., on a `(region, status)` index, `lookup_prefix(&[b"us-east"])` returns all keys where `region = "us-east"` regardless of status. Uses `starts_with()` on the B-Tree range to avoid false matches from the `0xFF` upper-bound trick, which breaks if field values contain bytes >= `0xFF`.

(&self, prefix_values: &[&[u8]])

Source from the content-addressed store, hash-verified

204 /// the `0xFF` upper-bound trick, which breaks if field values contain
205 /// bytes >= `0xFF`.
206 pub fn lookup_prefix(&self, prefix_values: &[&[u8]]) -> Vec<&[u8]> {
207 let prefix = Self::build_key(prefix_values);
208 let mut results = Vec::new();
209 for (composite_key, primary_keys) in self.tree.range(prefix.clone()..) {
210 if !composite_key.starts_with(&prefix) {
211 break;
212 }
213 for pk in primary_keys {
214 results.push(pk.as_slice());
215 }
216 }
217 results
218 }
219
220 /// Total number of index entries.
221 pub fn entry_count(&self) -> usize {

Callers 2

scanMethod · 0.80

Calls 4

rangeMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
as_sliceMethod · 0.45

Tested by 1