@@ -12,7 +12,48 @@ use hash32::{BuildHasher, BuildHasherDefault, FnvHasher, Hash, Hasher};
12
12
13
13
use crate :: Vec ;
14
14
15
- /// An `IndexMap` using the default FNV hasher
15
+ /// A [`heaples::IndexMap`](./struct.IndexMap.html) using the default FNV hasher
16
+ ///
17
+ /// A list of all Methods and Traits available for `FnvIndexMap` can be found in
18
+ /// the [`heapless::IndexMap`](./struct.IndexMap.html) documentation.
19
+ ///
20
+ /// # Examples
21
+ /// ```
22
+ /// use heapless::FnvIndexMap;
23
+ /// use heapless::consts::*;
24
+ ///
25
+ /// // A hash map with a capacity of 16 key-value pairs allocated on the stack
26
+ /// let mut book_reviews = FnvIndexMap::<_, _, U16>::new();
27
+ ///
28
+ /// // review some books.
29
+ /// book_reviews.insert("Adventures of Huckleberry Finn", "My favorite book.").unwrap();
30
+ /// book_reviews.insert("Grimms' Fairy Tales", "Masterpiece.").unwrap();
31
+ /// book_reviews.insert("Pride and Prejudice", "Very enjoyable.").unwrap();
32
+ /// book_reviews.insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.").unwrap();
33
+ ///
34
+ /// // check for a specific one.
35
+ /// if !book_reviews.contains_key("Les Misérables") {
36
+ /// println!("We've got {} reviews, but Les Misérables ain't one.",
37
+ /// book_reviews.len());
38
+ /// }
39
+ ///
40
+ /// // oops, this review has a lot of spelling mistakes, let's delete it.
41
+ /// book_reviews.remove("The Adventures of Sherlock Holmes");
42
+ ///
43
+ /// // look up the values associated with some keys.
44
+ /// let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
45
+ /// for book in &to_find {
46
+ /// match book_reviews.get(book) {
47
+ /// Some(review) => println!("{}: {}", book, review),
48
+ /// None => println!("{} is unreviewed.", book)
49
+ /// }
50
+ /// }
51
+ ///
52
+ /// // iterate over everything.
53
+ /// for (book, review) in &book_reviews {
54
+ /// println!("{}: \"{}\"", book, review);
55
+ /// }
56
+ /// ```
16
57
pub type FnvIndexMap < K , V , N > = IndexMap < K , V , N , BuildHasherDefault < FnvHasher > > ;
17
58
18
59
#[ derive( Clone , Copy , Eq , PartialEq ) ]
@@ -286,9 +327,15 @@ where
286
327
287
328
/// Fixed capacity [`IndexMap`](https://docs.rs/indexmap/1/indexmap/map/struct.IndexMap.html)
288
329
///
330
+ /// Note that you cannot use `IndexMap` directly, since it is generic around the hashing algorithm
331
+ /// in use. Pick a concrete instantiation like [`FnvIndexMap`](./type.FnvIndexMap.html) instead
332
+ /// or create your own.
333
+ ///
289
334
/// Note that the capacity of the `IndexMap` must be a power of 2.
290
335
///
291
336
/// # Examples
337
+ /// Since `IndexMap` cannot be used directly, we're using its `FnvIndexMap` instantiation
338
+ /// for this example.
292
339
///
293
340
/// ```
294
341
/// use heapless::FnvIndexMap;
0 commit comments