|
1 |
| -//! This crate provides `BinaryHeap` which is backward-compatible with `std::collections::BinaryHeap`. |
| 1 | +//! This crate provides [`BinaryHeap`] which is backward-compatible with |
| 2 | +//! [`std::collections::BinaryHeap`]. |
2 | 3 | //!
|
3 | 4 | //! Added features include:
|
4 | 5 | //! * Heaps other than max heap.
|
5 |
| -//! * Optional `serde` feature. |
| 6 | +//! * Optional [`serde`] feature. |
| 7 | +//! |
| 8 | +//! [`BinaryHeap`]: struct.BinaryHeap.html |
| 9 | +//! [`std::collections::BinaryHeap`]: |
| 10 | +//! https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html |
| 11 | +//! [`serde`]: https://docs.serde.rs/serde/ |
6 | 12 | //!
|
7 | 13 | //! # Quick start
|
8 | 14 | //!
|
9 | 15 | //! ## Max/Min Heap
|
10 | 16 | //!
|
11 |
| -//! For max heap, `BiaryHeap::from_vec()` is the most versatile way to create a heap. |
| 17 | +//! For max heap, [`BinaryHeap::from_vec()`] is the most versatile way to create a heap. |
12 | 18 | //!
|
13 | 19 | //! ```rust
|
14 |
| -//! use binary_heap_plus::*; |
| 20 | +//! use binary_heap_plus::*; |
15 | 21 | //!
|
16 |
| -//! // max heap |
17 |
| -//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(vec![]); |
18 |
| -//! // max heap with initial capacity |
19 |
| -//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(Vec::with_capacity(16)); |
20 |
| -//! // max heap from iterator |
21 |
| -//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec((0..42).collect()); |
22 |
| -//! assert_eq!(h.pop(), Some(41)); |
| 22 | +//! // max heap |
| 23 | +//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(vec![]); |
| 24 | +//! // max heap with initial capacity |
| 25 | +//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(Vec::with_capacity(16)); |
| 26 | +//! // max heap from iterator |
| 27 | +//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec((0..42).collect()); |
| 28 | +//! assert_eq!(h.pop(), Some(41)); |
23 | 29 | //! ```
|
24 | 30 | //!
|
25 | 31 | //! Min heap is similar, but requires type annotation.
|
26 | 32 | //!
|
27 | 33 | //! ```rust
|
28 |
| -//! use binary_heap_plus::*; |
| 34 | +//! use binary_heap_plus::*; |
29 | 35 | //!
|
30 |
| -//! // min heap |
31 |
| -//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(vec![]); |
32 |
| -//! // min heap with initial capacity |
33 |
| -//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(Vec::with_capacity(16)); |
34 |
| -//! // min heap from iterator |
35 |
| -//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec((0..42).collect()); |
36 |
| -//! assert_eq!(h.pop(), Some(0)); |
| 36 | +//! // min heap |
| 37 | +//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(vec![]); |
| 38 | +//! // min heap with initial capacity |
| 39 | +//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(Vec::with_capacity(16)); |
| 40 | +//! // min heap from iterator |
| 41 | +//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec((0..42).collect()); |
| 42 | +//! assert_eq!(h.pop(), Some(0)); |
37 | 43 | //! ```
|
38 | 44 | //!
|
| 45 | +//! [`BinaryHeap::from_vec()`]: struct.BinaryHeap.html#method.from_vec |
| 46 | +//! |
39 | 47 | //! ## Custom Heap
|
40 | 48 | //!
|
41 |
| -//! For custom heap, `BinaryHeap::from_vec_cmp()` works in a similar way to max/min heap. The only difference is that you add the comparator closure with apropriate signature. |
| 49 | +//! For custom heap, [`BinaryHeap::from_vec_cmp()`] works in a similar way to max/min heap. The |
| 50 | +//! only difference is that you add the comparator closure with apropriate signature. |
42 | 51 | //!
|
43 | 52 | //! ```rust
|
44 |
| -//! use binary_heap_plus::*; |
| 53 | +//! use binary_heap_plus::*; |
45 | 54 | //!
|
46 |
| -//! // custom heap: ordered by second value (_.1) of the tuples; min first |
47 |
| -//! let mut h = BinaryHeap::from_vec_cmp( |
48 |
| -//! vec![(1, 5), (3, 2), (2, 3)], |
49 |
| -//! |a: &(i32, i32), b: &(i32, i32)| b.1.cmp(&a.1), // comparator closure here |
50 |
| -//! ); |
51 |
| -//! assert_eq!(h.pop(), Some((3, 2))); |
| 55 | +//! // custom heap: ordered by second value (_.1) of the tuples; min first |
| 56 | +//! let mut h = BinaryHeap::from_vec_cmp( |
| 57 | +//! vec![(1, 5), (3, 2), (2, 3)], |
| 58 | +//! |a: &(i32, i32), b: &(i32, i32)| b.1.cmp(&a.1), // comparator closure here |
| 59 | +//! ); |
| 60 | +//! assert_eq!(h.pop(), Some((3, 2))); |
52 | 61 | //! ```
|
53 | 62 | //!
|
| 63 | +//! [`BinaryHeap::from_vec_cmp()`]: struct.BinaryHeap.html#method.from_vec_cmp |
| 64 | +//! |
54 | 65 | //! # Constructers
|
55 | 66 | //!
|
56 | 67 | //! ## Generic methods to create different kind of heaps from initial `vec` data.
|
57 | 68 | //!
|
58 |
| -//! * `BinaryHeap::from_vec(vec)` |
59 |
| -//! * `BinaryHeap::from_vec_cmp(vec, cmp)` |
| 69 | +//! * [`BinaryHeap::from_vec`]`(vec)` |
| 70 | +//! * [`BinaryHeap::from_vec_cmp`]`(vec, cmp)` |
| 71 | +//! |
| 72 | +//! [`BinaryHeap::from_vec`]: struct.BinaryHeap.html#method.from_vec |
| 73 | +//! [`BinaryHeap::from_vec_cmp`]: struct.BinaryHeap.html#method.from_vec_cmp |
60 | 74 | //!
|
61 | 75 | //! ```
|
62 | 76 | //! use binary_heap_plus::*;
|
|
87 | 101 | //!
|
88 | 102 | //! ## Dedicated methods to create different kind of heaps
|
89 | 103 | //!
|
90 |
| -//! * `BinaryHeap::new()` creates a max heap. |
91 |
| -//! * `BinaryHeap::new_min()` creates a min heap. |
92 |
| -//! * `BinaryHeap::new_by()` creates a heap sorted by the given closure. |
93 |
| -//! * `BinaryHeap::new_by_key()` creates a heap sorted by the key generated by the given closure. |
| 104 | +//! * [`BinaryHeap::new()`] creates a max heap. |
| 105 | +//! * [`BinaryHeap::new_min()`] creates a min heap. |
| 106 | +//! * [`BinaryHeap::new_by()`] creates a heap sorted by the given closure. |
| 107 | +//! * [`BinaryHeap::new_by_key()`] creates a heap sorted by the key generated by the given closure. |
94 | 108 | //!
|
| 109 | +//! [`BinaryHeap::new()`]: struct.BinaryHeap.html#method.new |
| 110 | +//! [`BinaryHeap::new_min()`]: struct.BinaryHeap.html#method.new_min |
| 111 | +//! [`BinaryHeap::new_by()`]: struct.BinaryHeap.html#method.new_by |
| 112 | +//! [`BinaryHeap::new_by_key()`]: struct.BinaryHeap.html#method.new_by_key |
95 | 113 |
|
96 | 114 | mod binary_heap;
|
97 | 115 | pub use crate::binary_heap::*;
|
|
0 commit comments