Priority queues, deques… in OCaml with containers
OCaml's standard library has no priority queue, no double-ended queue and no dynamic array. In Basthon, the containers library fills this gap:
ocaml
#require "containers-data";;
module Heap = CCHeap.Make (struct type t = int let leq = ( <= ) end);;
Heap.to_list_sorted (Heap.of_list [ 5; 3; 8; 1 ]);;
let d = CCDeque.of_list [ 2; 3 ];;
CCDeque.push_front d 1;;It notably provides heaps (CCHeap), deques (CCDeque), persistent queues (CCFQueue), dynamic arrays (CCVector), bit vectors (CCBV), as well as many extensions of the standard library (CCList, CCString…). The example notebook uses them for heap sort, Dijkstra's algorithm, a breadth-first search or the sieve of Eratosthenes.
