aboutsummaryrefslogtreecommitdiff
path: root/src/tools.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2018-02-12 15:22:56 +0100
committerSébastien Dailly <sebastien@chimrod.com>2018-02-12 15:22:56 +0100
commit5f94836f4d1adca31c502706831b9ac600c3f41f (patch)
tree4e00c09f198667bfb88965d8c9535e23dc70bbf1 /src/tools.ml
parentbb48738c4111f5f4e2faa40fe67ae1b8b9d7c2eb (diff)
Update licence, add opam script
Diffstat (limited to 'src/tools.ml')
-rwxr-xr-xsrc/tools.ml112
1 files changed, 17 insertions, 95 deletions
diff --git a/src/tools.ml b/src/tools.ml
index 8481d59..cfd17cd 100755
--- a/src/tools.ml
+++ b/src/tools.ml
@@ -1,3 +1,20 @@
+(*
+This file is part of licht.
+
+licht is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+licht is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with licht. If not, see <http://www.gnu.org/licenses/>.
+*)
+
let u = UTF8.from_utf8string
module Option = struct
@@ -37,11 +54,6 @@ module String = struct
String.sub str 0 p, String.sub str (p + 1) (slen - p - 1)
end
- let cut str ~by:sep = begin
- try String.sub str 0 @@ String.index str sep with
- | Not_found -> str
- end
-
let string_of_ints v = begin
let buff = Buffer.create 1 in
let rec convert value = begin
@@ -107,15 +119,6 @@ module List = struct
end
end
- let rec findOpt p = begin function
- | [] -> None
- | x::l ->
- if p x then
- Some(x)
- else
- findOpt p l
- end
-
and find_map2 p = begin function
| [] -> raise Not_found
| x::l ->
@@ -124,34 +127,6 @@ module List = struct
end
end
- (** Convert the list [l] as an array *)
- let to_array l = begin
- let elems = ref l in
- let build = fun _ ->
- begin match (!elems) with
- | [] -> assert false
- | hd::tl ->
- elems := tl;
- hd
- end
- in Array.init (List.length l) build
- end
-
- let linearize elems = begin
- let rec _linearize acc (elems:'a list list) : 'a list = begin
- let split (hds, tls) = function
- | hd::tl -> hd::hds, tl::tls
- | [] -> hds, tls
- in
- match elems with
- | [] -> acc
- | elems ->
- let acc, tls = List.fold_left split (acc, []) elems in
- _linearize acc tls
- end in
- List.rev @@ _linearize [] elems
- end
-
end
module Tuple2 = struct
@@ -179,29 +154,6 @@ module Tuple2 = struct
end
-module Tuple3 = struct
-
- let fst (a, b, c) = a
-
- let snd (a, b, c) = b
-
- let thd (a, b, c) = c
-
- let map f (a, b, c) = (f a, f b, f c)
-
- let map1 f (a, b, c) = (f a, b, c)
-
- let map2 f (a, b, c) = (a, f b, c)
-
- let map3 f (a, b, c) = (a, b, f c)
-
- let replace1 v (a, b, c) = (v, b, c)
-
- let replace2 v (a, b, c) = (a, v, c)
-
- let replace3 v (a, b, c) = (a, b, v)
-end
-
module NCurses = struct
type mouse_event =
@@ -268,36 +220,6 @@ module type COMPARABLE_TYPE = sig
end
-module ArrayMap(Ord: COMPARABLE_TYPE) = struct
-
- type 'a key = 'a Ord.t
-
- type t = Val : ('a key * 'a) array -> t
-
- let find: type a. a key -> t -> a = begin fun k (Val map) ->
- let rec find_ idx : a = begin
- let x, v = Array.get map idx in
- match Ord.comp x k with
- | Eq -> v
- | Lt -> find_ ((2 * idx) + 1)
- | Gt -> find_ ((2 * idx) + 2)
- end in
- find_ 0
- end
-
- let from_list l = begin
- let compare (key_x, _) (key_y, _) = match Ord.comp key_x key_y with
- | Eq -> 0
- | Lt -> -1
- | Gt -> 1
- in
- let arr = List.to_array l in
- Array.sort compare arr;
- Val arr
- end
-
-end
-
let fold_for f a b init =
let rec _fold res i = begin
if i >= b then res