Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Heap (data structure)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Programming language implementations== * The [[C++ Standard Library]] provides the {{mono|make_heap}}, {{mono|push_heap}} and {{mono|pop_heap}} algorithms for heaps (usually implemented as binary heaps), which operate on arbitrary random access [[iterator]]s. It treats the iterators as a reference to an array, and uses the array-to-heap conversion. It also provides the container adaptor {{mono|priority_queue}}, which wraps these facilities in a container-like class. However, there is no standard support for the replace, sift-up/sift-down, or decrease/increase-key operations. * The [[Boost (C++ libraries)|Boost C++ libraries]] include a heaps library. Unlike the STL, it supports decrease and increase operations, and supports additional types of heap: specifically, it supports ''d''-ary, binomial, Fibonacci, pairing and skew heaps. * There is a [https://github.com/valyala/gheap generic heap implementation] for [[C (programming language)|C]] and [[C++]] with [[D-ary heap]] and [[B-heap]] support. It provides an STL-like API. * The standard library of the [[D (programming language)|D programming language]] includes [https://dlang.org/phobos/std_container_binaryheap.html {{mono|std.container.BinaryHeap}}], which is implemented in terms of D's [https://tour.dlang.org/tour/en/basics/ranges ranges]. Instances can be constructed from any [https://dlang.org/phobos/std_range_primitives.html#isRandomAccessRange random-access range]. {{mono|BinaryHeap}} exposes an [https://dlang.org/phobos/std_range_primitives.html#isInputRange input range interface] that allows iteration with D's built-in {{mono|foreach}} statements and integration with the range-based API of the [https://dlang.org/phobos/std_algorithm.html {{mono|std.algorithm}} package]. * For [[Haskell]] there is the [https://hackage.haskell.org/package/heaps {{mono|Data.Heap}}] module. * The [[Java (programming language)|Java]] platform (since version 1.5) provides a binary heap implementation with the class {{Javadoc:SE|package=java.util|java/util|PriorityQueue}} in the [[Java Collections Framework]]. This class implements by default a min-heap; to implement a max-heap, programmer should write a custom comparator. There is no support for the replace, sift-up/sift-down, or decrease/increase-key operations. * [[Python (programming language)|Python]] has a [https://docs.python.org/library/heapq.html {{mono|heapq}}] module that implements a priority queue using a binary heap. The library exposes a heapreplace function to support k-way merging. Python only supports a min-heap implementation. * [[PHP]] has both max-heap ({{mono|SplMaxHeap}}) and min-heap ({{mono|SplMinHeap}}) as of version 5.3 in the Standard PHP Library. * [[Perl]] has implementations of binary, binomial, and Fibonacci heaps in the [https://metacpan.org/module/Heap {{mono|Heap}}] distribution available on [[CPAN]]. * The [[Go (programming language)|Go]] language contains a [http://golang.org/pkg/container/heap/ {{mono|heap}}] package with heap algorithms that operate on an arbitrary type that satisfies a given interface. That package does not support the replace, sift-up/sift-down, or decrease/increase-key operations. * Apple's [[Core Foundation]] library contains a [https://developer.apple.com/documentation/corefoundation/cfbinaryheap {{mono|CFBinaryHeap}}] structure. * [[Pharo]] has an implementation of a heap in the Collections-Sequenceable package along with a set of test cases. A heap is used in the implementation of the timer event loop. * The [[Rust (programming language)|Rust]] programming language has a binary max-heap implementation, [https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html {{mono|BinaryHeap}}], in the {{mono|collections}} module of its standard library. * [[.NET]] has [https://docs.microsoft.com/dotnet/api/system.collections.generic.priorityqueue-2 PriorityQueue] class which uses quaternary (d-ary) min-heap implementation. It is available from .NET 6.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)