#binary #heap #priority #queue

binary-heap-plus

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

9 releases

✓ Uses Rust 2018 edition

new 0.3.0 Jul 8, 2020
0.2.0 May 27, 2019
0.1.6 May 21, 2019
0.1.4 May 18, 2018

#61 in Data structures

Download history 490/week @ 2020-03-23 479/week @ 2020-03-30 553/week @ 2020-04-06 394/week @ 2020-04-13 450/week @ 2020-04-20 554/week @ 2020-04-27 788/week @ 2020-05-04 895/week @ 2020-05-11 611/week @ 2020-05-18 559/week @ 2020-05-25 387/week @ 2020-06-01 326/week @ 2020-06-08 861/week @ 2020-06-15 538/week @ 2020-06-22 503/week @ 2020-06-29 481/week @ 2020-07-06

2,409 downloads per month
Used in 3 crates

MIT license

64KB
766 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.

MSRV (Minimum Supported Rust Version)

This crate requires Rust 1.31.1 or later.

Changes

See CHANGELOG.md. https://github.com/sekineh/binary-heap-plus-rs/blob/master/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.

References

See the following discussions for the background of the crate:

Dependencies

~205KB