pub trait CaseInsensitiveLookup<V> {
// Required methods
fn get_ci(&self, key: &str) -> Option<&V>;
fn contains_key_ci(&self, key: &str) -> bool;
fn get_mut_ci(&mut self, key: &str) -> Option<&mut V>;
}Expand description
Helper trait for case-insensitive lookups on standard HashMap<String, V>
This trait provides extension methods for performing case-insensitive lookups on existing String-keyed HashMaps without requiring migration to CaseInsensitiveMap.
§Performance
- Best case: O(1) when exact case matches (uses HashMap’s fast path)
- Worst case: O(n) when case differs (iterates all keys to find match)
For hot paths (executed per-row or frequently), store normalized (lowercase) keys in the HashMap to guarantee O(1) lookups. This trait is most appropriate for:
- Small HashMaps (< 100 entries)
- Cold paths (planning phase, executed once per query)
- Cases where preserving original case in keys is important
See SemanticAnalyzer::variables for an example of the optimized pattern where
keys are normalized to lowercase on insertion, ensuring all lookups hit the O(1) fast path.
§Examples
use std::collections::HashMap;
use lance_graph::case_insensitive::CaseInsensitiveLookup;
let mut map = HashMap::new();
map.insert("Person".to_string(), 1);
assert_eq!(map.get_ci("person"), Some(&1));
assert_eq!(map.get_ci("PERSON"), Some(&1));
assert_eq!(map.get_ci("Person"), Some(&1));Required Methods§
Sourcefn get_ci(&self, key: &str) -> Option<&V>
fn get_ci(&self, key: &str) -> Option<&V>
Get a value with case-insensitive key lookup.
Returns Some(&V) if a key matches (case-insensitively), None otherwise.
Sourcefn contains_key_ci(&self, key: &str) -> bool
fn contains_key_ci(&self, key: &str) -> bool
Check if a key exists with case-insensitive lookup.
Sourcefn get_mut_ci(&mut self, key: &str) -> Option<&mut V>
fn get_mut_ci(&mut self, key: &str) -> Option<&mut V>
Get a mutable reference with case-insensitive key lookup.