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]])
| 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 { |