ocaml-lib / intset.ml

(** {1 Optimized integer sets} *)

module type T =
  sig
    type t
    val empty : t
    val is_empty : t -> bool
    val cardinal : t -> int
    val mem : int -> t -> bool
    val singleton : int -> t
    val add : int -> t -> t
    val remove : int -> t -> t
    val subset : t -> t -> bool
    val union : t -> t -> t
    val inter : t -> t -> t
    val diff : t -> t -> t
    val union_r : t list -> t
    val inter_r : t list -> t
    val fold : ('a -> int -> 'a) -> 'a -> t -> 'a
    val iter : (int -> unit) -> t -> unit
    val map : (int -> 'a) -> t -> 'a list
    val filter : (int -> bool) -> t -> t
    val elements : t -> int LSet.t
  end

module Cis : T =
(* Cis implementation of extents *)
  struct
    type t = Cis.t
    let empty = Cis.empty
    let is_empty = Cis.is_empty
    let cardinal = Cis.cardinal
    let mem = Cis.mem
    let singleton = Cis.singleton
    let add = Cis.add
    let remove = Cis.remove
    let subset = Cis.subset
    let union = Cis.union
    let inter = Cis.inter
    let diff = Cis.diff
    let union_r l = List.fold_left (fun res set -> union res set) empty l
    let inter_r = function
      | [] -> raise (Invalid_argument "Node.Ext.inter_r : empty list of sets")
      | set::sets -> List.fold_right (fun set res -> inter set res) sets set
    let fold = Cis.fold_left
    let iter = Cis.iter
    let map f ext = Cis.fold_left (fun res x -> f x::res) [] ext
    let filter p ext = List.fold_left (fun res x -> if p x then Cis.add x res else res) Cis.empty (Cis.elements ext)
    let elements = Cis.elements
  end

module LSet : T =
(* LSet implementation of extents *)
  struct
    type t = int LSet.t
    let empty = LSet.empty ()
    let is_empty = LSet.is_empty
    let cardinal = LSet.cardinal
    let mem = LSet.mem
    let singleton = LSet.singleton
    let add = LSet.add
    let remove = LSet.remove
    let subset = LSet.subset
    let union = LSet.union
    let inter = LSet.inter
    let diff = LSet.diff
    let union_r = LSet.union_r
    let inter_r = LSet.inter_r
    let fold = List.fold_left
    let iter = List.iter
    let map = List.map
    let filter = List.filter
    let elements l = l
  end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.