#priority-queue #binary-heap #heap #queue #priority #binary

binary-heap-plus

Enhanced version of std::collections::BinaryHeap that supports max, min, and custom-order heaps

13 releases

0.5.0 Sep 30, 2022
0.4.1 Jan 6, 2021
0.4.0 Sep 29, 2020
0.3.1 Sep 24, 2020
0.1.4 May 18, 2018

#129 in Data structures

Download history 18292/week @ 2023-12-13 10835/week @ 2023-12-20 8016/week @ 2023-12-27 14459/week @ 2024-01-03 21346/week @ 2024-01-10 30745/week @ 2024-01-17 32216/week @ 2024-01-24 27429/week @ 2024-01-31 22482/week @ 2024-02-07 29981/week @ 2024-02-14 38147/week @ 2024-02-21 45278/week @ 2024-02-28 28363/week @ 2024-03-06 33559/week @ 2024-03-13 29769/week @ 2024-03-20 21924/week @ 2024-03-27

119,316 downloads per month
Used in 21 crates (15 directly)

MIT license

80KB
890 lines

binary-heap-plus-rs

Rust

Enhancement over Rust's std::collections::BinaryHeap.

It supports the following heaps and still maintains backward compatibility.

  • Max heap
    • Use BinaryHeap::new() or ::with_capacity()
  • Min heap
    • Use BinaryHeap::new_min() or ::with_capacity_min()
  • Heap ordered by closure
    • Use BinaryHeap::new_by() or ::with_capacity_by()
  • Heap ordered by key generated by closure
    • Use BinaryHeap::new_by_key() or ::with_capacity_by_key()

Other notable added methods are:

  • BinaryHeap::from_vec_cmp() and BinaryHeap::from_vec() for more generic construction.
  • .into_iter_sorted() which is less-surprising version of .into_iter(). The implementation is backported from std.
  • .replace_cmp() which replace the comparator of the existing heap.

Compatibility and MSRV (Minimum Supported Rust Version)

This crate is based on the standard library's implementation of BinaryHeap from Rust 1.62.0.

The minimum supported Rust version is 1.56.0.

Changes

See CHANGELOG.md.

Thanks

  • I received many valuable feedback from Pre-RFC thread [1].
    • The current design is based on @ExpHP's suggestion that compiles on stable compiler.
    • DDOtten, steven099, CAD97, ExpHP, scottmcm, Nemo157 and gnzlbg, thanks for looking into the design!
  • @ulysseB sent me a first pull request!
  • @inesseq contributed feature serde1.
  • @davidli2010 contributed comparator update and unsafe perf optimization.

References

See the following discussions for the background of the crate:

Dependencies

~200KB