Pqueue.MakeMin(3)

πŸ’– Pqueue.MakeMin πŸ’–

okay bestie, welcome to the Pqueue.MakeMin(3) page straight outta the OCaml library. This is the functor energy you need when you want a min-priority queue and your elements are totally ordered. Slay. πŸ’…

✨ NAME ✨

  • Pqueue.MakeMin β€” Functor building an implementation of the min-priority queue structure given a totally ordered type for elements. No cap, that's the whole vibe.

🧚 Module 🧚

Pqueue.MakeMin β€” yes bestie, that's literally the module name. Iconic. πŸ‘‘

πŸ“š Documentation πŸ“š

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

Functor building an implementation of the min-priority queue structure given a totally ordered type for elements. It's giving "parameterized by your element type" realness.

Parameters:

  • "E" β€” Pqueue.OrderedType. That's the totally ordered type handing out the element ordering, periodt.

πŸ‘‘ Min-priority queues πŸ‘‘

  • type t β€” the type of priority queues.
  • type elt β€” the type of priority queue elements.
  • val create : unit -> t β€” returns a new priority queue, initially empty. Fresh out the box, bestie. ✨
  • val length : t -> int β€” returns 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. Lowkey a peek, no cap. πŸ‘€
  • 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. It's giving "you better check that queue first" energy. 😭
  • 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. Total reset, main character energy. 🫢
  • 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. So don't come for me about ordering, bestie β€” it's literally not specified. πŸ’€

⚠️ 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. So like... don't do it. Fr fr.
  • 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.


🫢 xoxo, your Unix bestie β€” this page is from OCamldoc, dated 2026-06-22, and yes it's the Pqueue.MakeMin(3) manual. Mwah. πŸ’…πŸŒΈ
πŸ“¦ where this page comes from