---
name: "Pqueue.MakeMin"
section: "3o"
platform: "linux"
package: "ocaml"
version: "5.5.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Pqueue.MakeMin"
---

# Pqueue.MakeMin(3o)

Functor building an implementation of the min-priority queue structure given a totally ordered type for elements.

## NAME

Pqueue.MakeMin - Functor building an implementation of the min-priority queue structure given a totally ordered type for elements.

## Module

Module   Pqueue.MakeMin

## Documentation

Module **MakeMin**\
  :  **(E : OrderedType) -\> sig end**

Functor building an implementation of the min-priority queue structure given a totally ordered type for elements.

**Parameters:**

"E"

**Pqueue.OrderedType**

### Min-priority queues

*type t*

The type of priority queues.

*type elt*

The type of priority queue elements.

*val create* :  **unit -\> t**

Return a new priority queue, initially empty.

*val length* :  **t -\> int**

Return the number of elements in a priority queue.

*val is\_empty* :  **t -\> bool**

**is\_empty q** is  **true** iff  **q** is empty, that is, iff  **length q = 0** .

*val add* :  **t -\> elt -\> unit**

**add q x** adds the element  **x** in the priority queue  **q** .

*val add\_iter* :  **t -\> ((elt -\> unit) -\> 'x -\> unit) -\> 'x -\> unit**

**add\_iter q iter x** adds each element of  **x** to the end of  **q** . This is  **iter (add q) x** .

*val min\_elt* :  **t -\> elt option**

**min\_elt q** is an element of  **q** with minimal priority or **None** if the queue is empty. The queue is not modified.

*val get\_min\_elt* :  **t -\> elt**

**get\_min\_elt q** returns an element of  **q** with minimal priority, or raises  **Invalid\_argument** if the queue is empty. The queue is not modified.

*val pop\_min* :  **t -\> elt option**

**pop\_min q** removes and returns an element in queue  **q** with minimal priority, or returns  **None** if the queue is empty.

*val remove\_min* :  **t -\> unit**

**remove\_min q** removes an element in queue  **q** with minimal priority. It does nothing if  **q** is empty.

*val clear* :  **t -\> unit**

**clear q** removes all elements from  **q** .

*val copy* :  **t -\> t**

**copy q** is a new priority queue with the same elements  **q** has.

### Conversions from other data structures

*val of\_array* :  **elt array -\> t**

**of\_array a** returns a new priority queue containing the elements of array  **a** . Runs in linear time.

*val of\_list* :  **elt list -\> t**

**of\_list l** returns a new priority queue containing the elements of list  **l** . Runs in linear time.

*val of\_iter* :  **((elt -\> unit) -\> 'x -\> unit) -\> 'x -\> t**

**of\_iter iter x** returns a new priority queue containing the elements of  **x** , obtained from  **iter** .

For example,  **of\_iter Seq.iter s** returns a new priority queue containing all the elements of the sequence  **s** (provided it is finite).

Runs in linear time (excluding the time spent in  **iter** ).

### Iteration

The order in which the elements of a priority queue are traversed is unspecified.

It is a programming error to mutate a priority queue (by adding or removing elements) during an iteration of the queue. Such an error may be detected and signaled by the backing dynamic array implementation, but this is not guaranteed.

*val iter\_unordered* :  **(elt -\> unit) -\> t -\> unit**

**iter\_unordered f q** applies  **f** to all elements in  **q** .  The order in which the elements are passed to  **f** is unspecified.

The behavior is not specified if the priority queue is modified by  **f** during the iteration.

*val fold\_unordered* :  **('acc -\> elt -\> 'acc) -\> 'acc -\> t -\> 'acc**

**fold\_unordered f accu q** is  **(f (... (f (f accu x1) x2) ...)**\
         **xn)** where  **x1,x2,...,xn** are the elements of  **q** . The order in which the elements are passed to  **f** is unspecified.

The behavior is not specified if the priority queue is modified by  **f** during the iteration.
