.TH "Set" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Set \- Sets over ordered types. .SH Module Module Set .SH Documentation .sp Module .BI "Set" : .B sig end .sp Sets over ordered types\&. .sp This module implements the set data structure, given a total ordering function over the set elements\&. All operations over sets are purely applicative (no side\-effects)\&. The implementation uses balanced binary trees, and is therefore reasonably efficient: insertion and membership take time logarithmic in the size of the set, for instance\&. .sp The .B Set\&.Make functor constructs implementations for any type, given a .B compare function\&. For instance: .B .B module IntPairs = .B struct .B type t = int * int .B let compare (x0,y0) (x1,y1) = .B match Pervasives\&.compare x0 x1 with .B 0 \-> Pervasives\&.compare y0 y1 .B | c \-> c .B end .B .B module PairsSet = Set\&.Make(IntPairs) .B .B let m = PairsSet\&.(empty |> add (2,3) |> add (5,7) |> add (11,13)) .B .sp This creates a new module .B PairsSet , with a new type .B PairsSet\&.t of sets of .B int * int \&. .sp .sp .sp .I module type OrderedType = .B sig end .sp Input signature of the functor .B Set\&.Make \&. .sp .I module type S = .B sig end .sp Output signature of the functor .B Set\&.Make \&. .sp .I module Make : .B functor (Ord : OrderedType) -> sig end .sp Functor building an implementation of the set structure given a totally ordered type\&. .sp