package ocplib_stuff
Source file ezCompat.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122# 1 "src/ocplib_stuff/ezCompat.4_03_0.ml" (**************************************************************************) (* *) (* Typerex Libraries *) (* *) (* Copyright 2011-2017 OCamlPro SAS *) (* *) (* All rights reserved. This file is distributed under the terms of *) (* the GNU Lesser General Public License version 2.1, with the *) (* special exception on linking described in the file LICENSE. *) (* *) (**************************************************************************) module Bytes = Bytes module Buffer = Buffer module String = struct include String let set = Bytes.set let lowercase = lowercase_ascii let uppercase = uppercase_ascii let capitalize = capitalize_ascii let uncapitalize s = uncapitalize_ascii s end module Char = struct include Char let uppercase = uppercase_ascii let lowercase = lowercase_ascii end module StringSet = struct module M = Set.Make(String) include M let of_list list = let map = ref empty in List.iter (fun x -> map := add x !map) list; !map let to_list set = let list = ref [] in iter (fun e -> list := e :: !list) set; List.rev !list end module StringMap = struct module M = Map.Make(String) include M let of_list list = let map = ref empty in List.iter (fun (x,y) -> map := add x y !map) list; !map let to_list map = let list = ref [] in iter (fun x y -> list := (x,y) :: !list) map; List.rev !list let to_list_of_keys map = let list = ref [] in iter (fun x _y -> list := x :: !list) map; List.rev !list end module IntSet : sig include Set.S with type elt = int end = struct module Set = Set.Make(struct type t = int let compare (x:int) y = compare x y end) include Set end module IntMap : sig include Map.S with type key = int val to_list: 'a t -> (int * 'a) list val to_list1: 'a t -> int list val to_list2: 'a t -> 'a list exception MinElt val min_elt: 'a t -> (key * 'a) option end = struct module Map = Map.Make(struct type t = int let compare (x:int) y = compare x y end) include Map let to_list map = let list = ref [] in iter (fun x y -> list := (x,y) :: !list) map; List.rev !list let to_list1 map = let list = ref [] in iter (fun x _y -> list := x :: !list) map; List.rev !list let to_list2 map = let list = ref [] in iter (fun _x y -> list := y :: !list) map; List.rev !list exception MinElt let exn_MinElt = MinElt let min_elt map = let x = ref None in try iter (fun key v -> x := Some (key, v); raise exn_MinElt) map; None with MinElt -> !x end