@@ -225,6 +225,15 @@ use std::vec;
225
225
/// assert!(heap.is_empty())
226
226
/// ```
227
227
///
228
+ /// A `BinaryHeap` with a known list of items can be initialized from an array:
229
+ ///
230
+ /// ```
231
+ /// use binary_heap_plus::BinaryHeap;
232
+ ///
233
+ /// // This will create a max-heap.
234
+ /// let heap = BinaryHeap::from([1, 5, 2]);
235
+ /// ```
236
+ ///
228
237
/// ## Min-heap
229
238
///
230
239
/// `BinaryHeap` can also act as a min-heap without requiring [`Reverse`] or a custom [`Ord`]
@@ -685,7 +694,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
685
694
///
686
695
/// // replace the comparor
687
696
/// heap.replace_cmp(Comparator { ascending: false });
688
- /// assert_eq!(heap.into_iter_sorted().collect::<Vec<_>>(), vec! [5, 3, 1]);
697
+ /// assert_eq!(heap.into_iter_sorted().collect::<Vec<_>>(), [5, 3, 1]);
689
698
/// ```
690
699
#[ inline]
691
700
pub fn replace_cmp ( & mut self , cmp : C ) {
@@ -755,7 +764,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
755
764
///
756
765
/// ```
757
766
/// use binary_heap_plus::BinaryHeap;
758
- /// let mut heap = BinaryHeap::from(vec! [1, 3]);
767
+ /// let mut heap = BinaryHeap::from([1, 3]);
759
768
///
760
769
/// assert_eq!(heap.pop(), Some(3));
761
770
/// assert_eq!(heap.pop(), Some(1));
@@ -828,7 +837,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
828
837
/// ```
829
838
/// use binary_heap_plus::BinaryHeap;
830
839
///
831
- /// let mut heap = BinaryHeap::from(vec! [1, 2, 4, 5, 7]);
840
+ /// let mut heap = BinaryHeap::from([1, 2, 4, 5, 7]);
832
841
/// heap.push(6);
833
842
/// heap.push(3);
834
843
///
@@ -1057,8 +1066,8 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
1057
1066
/// ```
1058
1067
/// use binary_heap_plus::BinaryHeap;
1059
1068
///
1060
- /// let mut a = BinaryHeap::from(vec! [-10, 1, 2, 3, 3]);
1061
- /// let mut b = BinaryHeap::from(vec! [-20, 5, 43]);
1069
+ /// let mut a = BinaryHeap::from([-10, 1, 2, 3, 3]);
1070
+ /// let mut b = BinaryHeap::from([-20, 5, 43]);
1062
1071
///
1063
1072
/// a.append(&mut b);
1064
1073
///
@@ -1089,7 +1098,7 @@ impl<T, C> BinaryHeap<T, C> {
1089
1098
///
1090
1099
/// ```
1091
1100
/// use binary_heap_plus::BinaryHeap;
1092
- /// let heap = BinaryHeap::from(vec! [1, 2, 3, 4]);
1101
+ /// let heap = BinaryHeap::from([1, 2, 3, 4]);
1093
1102
///
1094
1103
/// // Print 1, 2, 3, 4 in arbitrary order
1095
1104
/// for x in heap.iter() {
@@ -1112,9 +1121,9 @@ impl<T, C> BinaryHeap<T, C> {
1112
1121
///
1113
1122
/// ```
1114
1123
/// use binary_heap_plus::BinaryHeap;
1115
- /// let heap = BinaryHeap::from(vec! [1, 2, 3, 4, 5]);
1124
+ /// let heap = BinaryHeap::from([1, 2, 3, 4, 5]);
1116
1125
///
1117
- /// assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), vec! [5, 4]);
1126
+ /// assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), [5, 4]);
1118
1127
/// ```
1119
1128
// #[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
1120
1129
pub fn into_iter_sorted ( self ) -> IntoIterSorted < T , C > {
@@ -1268,7 +1277,7 @@ impl<T, C> BinaryHeap<T, C> {
1268
1277
///
1269
1278
/// ```
1270
1279
/// use binary_heap_plus::BinaryHeap;
1271
- /// let heap = BinaryHeap::from(vec! [1, 2, 3, 4, 5, 6, 7]);
1280
+ /// let heap = BinaryHeap::from([1, 2, 3, 4, 5, 6, 7]);
1272
1281
/// let vec = heap.into_vec();
1273
1282
///
1274
1283
/// // Will print in some order
@@ -1290,7 +1299,7 @@ impl<T, C> BinaryHeap<T, C> {
1290
1299
///
1291
1300
/// ```
1292
1301
/// use binary_heap_plus::BinaryHeap;
1293
- /// let heap = BinaryHeap::from(vec! [1, 3]);
1302
+ /// let heap = BinaryHeap::from([1, 3]);
1294
1303
///
1295
1304
/// assert_eq!(heap.len(), 2);
1296
1305
/// ```
@@ -1337,7 +1346,7 @@ impl<T, C> BinaryHeap<T, C> {
1337
1346
///
1338
1347
/// ```
1339
1348
/// use binary_heap_plus::BinaryHeap;
1340
- /// let mut heap = BinaryHeap::from(vec! [1, 3]);
1349
+ /// let mut heap = BinaryHeap::from([1, 3]);
1341
1350
///
1342
1351
/// assert!(!heap.is_empty());
1343
1352
///
@@ -1363,7 +1372,7 @@ impl<T, C> BinaryHeap<T, C> {
1363
1372
///
1364
1373
/// ```
1365
1374
/// use binary_heap_plus::BinaryHeap;
1366
- /// let mut heap = BinaryHeap::from(vec! [1, 3]);
1375
+ /// let mut heap = BinaryHeap::from([1, 3]);
1367
1376
///
1368
1377
/// assert!(!heap.is_empty());
1369
1378
///
@@ -1693,7 +1702,7 @@ impl<T, C> IntoIterator for BinaryHeap<T, C> {
1693
1702
///
1694
1703
/// ```
1695
1704
/// use binary_heap_plus::BinaryHeap;
1696
- /// let heap = BinaryHeap::from(vec! [1, 2, 3, 4]);
1705
+ /// let heap = BinaryHeap::from([1, 2, 3, 4]);
1697
1706
///
1698
1707
/// // Print 1, 2, 3, 4 in arbitrary order
1699
1708
/// for x in heap.into_iter() {
0 commit comments