Look up the value stored for `key`. If it exists, return the stored key-value pair. Otherwise, return the last key-value pair with a key that is less than or equal to `key`. If no stored keys are less than or equal to `key`, return `None`.
(
&self,
key: K,
forest: &MapForest<K, V>,
comp: &C,
)
| 115 | /// |
| 116 | /// If no stored keys are less than or equal to `key`, return `None`. |
| 117 | pub fn get_or_less<C: Comparator<K>>( |
| 118 | &self, |
| 119 | key: K, |
| 120 | forest: &MapForest<K, V>, |
| 121 | comp: &C, |
| 122 | ) -> Option<(K, V)> { |
| 123 | self.root.expand().and_then(|root| { |
| 124 | let mut path = Path::default(); |
| 125 | match path.find(key, root, &forest.nodes, comp) { |
| 126 | Some(v) => Some((key, v)), |
| 127 | None => path.prev(root, &forest.nodes), |
| 128 | } |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | /// Insert `key, value` into the map and return the old value stored for `key`, if any. |
| 133 | pub fn insert<C: Comparator<K>>( |