<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFBinaryHeap",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFBinaryHeapRef"
  },
  "title" : "CFBinaryHeap"
}
-->

# CFBinaryHeap

```
class CFBinaryHeap
```

## Overview

`CFBinaryHeap` implements a container that stores values sorted using a binary search algorithm. All binary heaps are mutable; there is not a separate immutable variety. Binary heaps can be useful as priority queues.

## Topics

### CFBinaryHeap Miscellaneous Functions

[`CFBinaryHeapAddValue(_:_:)`](/documentation/CoreFoundation/CFBinaryHeapAddValue(_:_:))

Adds a value to a binary heap.

[`CFBinaryHeapApplyFunction(_:_:_:)`](/documentation/CoreFoundation/CFBinaryHeapApplyFunction(_:_:_:))

Iteratively applies a function to all the values in a binary heap.

[`CFBinaryHeapContainsValue(_:_:)`](/documentation/CoreFoundation/CFBinaryHeapContainsValue(_:_:))

Returns whether a given value is in a binary heap.

[`CFBinaryHeapCreate(_:_:_:_:)`](/documentation/CoreFoundation/CFBinaryHeapCreate(_:_:_:_:))

Creates a new mutable or fixed-mutable binary heap.

[`CFBinaryHeapCreateCopy(_:_:_:)`](/documentation/CoreFoundation/CFBinaryHeapCreateCopy(_:_:_:))

Creates a new mutable or fixed-mutable binary heap with the values from a pre-existing binary heap.

[`CFBinaryHeapGetCount(_:)`](/documentation/CoreFoundation/CFBinaryHeapGetCount(_:))

Returns the number of values currently in a binary heap.

[`CFBinaryHeapGetCountOfValue(_:_:)`](/documentation/CoreFoundation/CFBinaryHeapGetCountOfValue(_:_:))

Counts the number of times a given value occurs in a binary heap.

[`CFBinaryHeapGetMinimum(_:)`](/documentation/CoreFoundation/CFBinaryHeapGetMinimum(_:))

Returns the minimum value in a binary heap.

[`CFBinaryHeapGetMinimumIfPresent(_:_:)`](/documentation/CoreFoundation/CFBinaryHeapGetMinimumIfPresent(_:_:))

Returns the minimum value in a binary heap, if present.

[`CFBinaryHeapGetTypeID()`](/documentation/CoreFoundation/CFBinaryHeapGetTypeID())

Returns the type identifier of the `CFBinaryHeap` opaque type.

[`CFBinaryHeapGetValues(_:_:)`](/documentation/CoreFoundation/CFBinaryHeapGetValues(_:_:))

Copies all the values from a binary heap into a sorted C array.

[`CFBinaryHeapRemoveAllValues(_:)`](/documentation/CoreFoundation/CFBinaryHeapRemoveAllValues(_:))

Removes all values from a binary heap, making it empty.

[`CFBinaryHeapRemoveMinimumValue(_:)`](/documentation/CoreFoundation/CFBinaryHeapRemoveMinimumValue(_:))

Removes the minimum value from a binary heap.

### Callbacks

[`CFBinaryHeapApplierFunction`](/documentation/CoreFoundation/CFBinaryHeapApplierFunction)

Callback function used to apply a function to all members of a binary heap.

[`compare`](/documentation/CoreFoundation/CFBinaryHeapCallBacks/compare)

The callback used to compare values in the binary heap in some operations. This field cannot be `NULL`.

[`copyDescription`](/documentation/CoreFoundation/CFBinaryHeapCallBacks/copyDescription)

Callback function used to get a description of a value in a binary heap.

[`release`](/documentation/CoreFoundation/CFBinaryHeapCallBacks/release)

Callback function used to release a value before it is removed from a binary heap.

[`retain`](/documentation/CoreFoundation/CFBinaryHeapCallBacks/retain)

Callback function used to retain a value being added to a binary heap.

[`version`](/documentation/CoreFoundation/CFBinaryHeapCallBacks/version)

The version number of the structure type being passed in as a parameter to the `CFBinaryHeap` creation functions. This structure is version `0`.

### Data Types

[`CFBinaryHeapCallBacks`](/documentation/CoreFoundation/CFBinaryHeapCallBacks)

Structure containing the callbacks for values for a `CFBinaryHeap` object.

[`CFBinaryHeapCompareContext`](/documentation/CoreFoundation/CFBinaryHeapCompareContext)

Not used.

### Constants

[Predefined Callback Structures](/documentation/CoreFoundation/cfbinaryheap-predefined-callback-structures)

`CFBinaryHeap` provides some predefined callbacks for your convenience.

## See Also

  [Collections Programming Topics](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Collections.html#//apple_ref/doc/uid/10000034i)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)