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 qistrueiffqis empty, that is, ifflength q = 0.val add : t -> elt -> unitβadd q xadds the elementxin the priority queueq.val add_iter : t -> ((elt -> unit) -> 'x -> unit) -> 'x -> unitβadd_iter q iter xadds each element ofxto the end ofq. This isiter (add q) x.val min_elt : t -> elt optionβmin_elt qis an element ofqwith minimal priority orNoneif the queue is empty. The queue is not modified. Lowkey a peek, no cap. πval get_min_elt : t -> eltβget_min_elt qreturns an element ofqwith minimal priority, or raisesInvalid_argumentif 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 qremoves and returns an element in queueqwith minimal priority, or returnsNoneif the queue is empty.val remove_min : t -> unitβremove_min qremoves an element in queueqwith minimal priority. It does nothing ifqis empty.val clear : t -> unitβclear qremoves all elements fromq. Total reset, main character energy. π«Άval copy : t -> tβcopy qis a new priority queue with the same elementsqhas.
π¦ Conversions from other data structures π¦
val of_array : elt array -> tβof_array areturns a new priority queue containing the elements of arraya. Runs in linear time.val of_list : elt list -> tβof_list lreturns a new priority queue containing the elements of listl. Runs in linear time.val of_iter : ((elt -> unit) -> 'x -> unit) -> 'x -> tβof_iter iter xreturns a new priority queue containing the elements ofx, obtained fromiter.
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 qappliesfto all elements inq. The order in which the elements are passed tofis 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 qis(f (... (f (f accu x1) x2) ...) xn)wherex1,x2,...,xnare the elements ofq. The order in which the elements are passed tofis 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
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms