@@ -190,33 +190,38 @@ impl<K: Ord, V> TreeMap<K, V> {
190
190
}
191
191
192
192
impl < K , V > TreeMap < K , V > {
193
- /// Return the value for which f(key) returns Equal. f is invoked
194
- /// with current key and helps to navigate the tree
193
+ /// Return the value for which `f(key)` returns `Equal`. `f` is invoked
194
+ /// with current key and guides tree navigation. That means `f` should
195
+ /// be aware of natural ordering of the tree.
195
196
///
196
197
/// # Example
197
198
///
198
199
/// ```
199
- /// use std::ascii::StrAsciiExt ;
200
+ /// use collections::treemap::TreeMap ;
200
201
///
201
- /// let mut t = collections::treemap::TreeMap::new();
202
- /// t.insert("Content-Type", "application/xml");
203
- /// t.insert("User-Agent", "Curl-Rust/0.1");
202
+ /// fn get_headers() -> TreeMap<String, String> {
203
+ /// let mut result = TreeMap::new();
204
+ /// result.insert("Content-Type".to_string(), "application/xml".to_string());
205
+ /// result.insert("User-Agent".to_string(), "Curl-Rust/0.1".to_string());
206
+ /// result
207
+ /// }
204
208
///
205
- /// let ua_key = "user-agent";
206
- /// let ua = t.find_with(|&k| {
207
- /// ua_key.cmp(&k.to_ascii_lower().as_slice())
209
+ /// let headers = get_headers();
210
+ /// let ua_key = "User-Agent";
211
+ /// let ua = headers.find_with(|k| {
212
+ /// ua_key.cmp(&k.as_slice())
208
213
/// });
209
214
///
210
- /// assert_eq!(*ua.unwrap(), "Curl-Rust/0.1");
215
+ /// assert_eq!(( *ua.unwrap()).as_slice (), "Curl-Rust/0.1");
211
216
/// ```
212
217
#[ inline]
213
218
pub fn find_with < ' a > ( & ' a self , f: |& K | -> Ordering ) -> Option < & ' a V > {
214
219
tree_find_with ( & self . root , f)
215
220
}
216
221
217
- /// Return the value for which f(key) returns Equal. f is invoked
218
- /// with current key and helps to navigate the tree
219
- ///
222
+ /// Return the value for which ` f(key)` returns ` Equal`. `f` is invoked
223
+ /// with current key and guides tree navigation. That means `f` should
224
+ /// be aware of natural ordering of the tree.
220
225
/// # Example
221
226
///
222
227
/// ```
@@ -913,14 +918,9 @@ fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
913
918
}
914
919
}
915
920
916
- // Next 2 functions have the same conventions
917
- //
918
- // The only difference is that non-mutable version uses loop instead
919
- // of recursion (performance considerations)
920
- // It seems to be impossible to avoid recursion with mutability
921
- //
922
- // So convention is that comparator is gets at input current key
923
- // and returns search_key cmp cur_key (i.e. search_key.cmp(cur_key))
921
+ // Next 2 functions have the same convention: comparator gets
922
+ // at input current key and returns search_key cmp cur_key
923
+ // (i.e. search_key.cmp(&cur_key))
924
924
fn tree_find_with < ' r , K , V > ( node : & ' r Option < Box < TreeNode < K , V > > > ,
925
925
f: |& K | -> Ordering ) -> Option < & ' r V > {
926
926
let mut current: & ' r Option < Box < TreeNode < K , V > > > = node;
0 commit comments