summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
authorJon French2019-03-14 13:56:37 +0000
committerJon French2019-03-14 13:56:37 +0000
commit0d88c148a2a068a95b5fc3d5c25b599faf3e75a0 (patch)
treecb507bee25582f503ae4047ce32558352aeb8b27 /src/util.ml
parent4f14ccb421443dbc10b88e190526dda754f324aa (diff)
parentec8cad1daa76fb265014d3d313173905925c9922 (diff)
Merge branch 'sail2' into rmem_interpreter
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/util.ml b/src/util.ml
index 0ff00df1..703bbc1f 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -149,11 +149,16 @@ let rec power i tothe =
then 1
else i * power i (tothe - 1)
-let rec assoc_maybe eq l k =
+let rec assoc_equal_opt eq k l =
match l with
| [] -> None
- | (k',v)::l -> if (eq k k') then Some v else assoc_maybe eq l k
+ | (k',v)::l -> if (eq k k') then Some v else assoc_equal_opt eq k l
+let rec assoc_compare_opt cmp k l =
+ match l with
+ | [] -> None
+ | (k',v)::l -> if cmp k k' = 0 then Some v else assoc_compare_opt cmp k l
+
let rec compare_list f l1 l2 =
match (l1,l2) with
| ([],[]) -> 0
@@ -324,18 +329,7 @@ module IntIntSet = Set.Make(
type t = int * int
end )
-
-module ExtraSet = functor (S : Set.S) ->
- struct
- let add_list s l = List.fold_left (fun s x -> S.add x s) s l
- let from_list l = add_list S.empty l
- let list_union l = List.fold_left S.union S.empty l
- let list_inter = function s :: l -> List.fold_left S.inter s l
- | [] -> raise (Failure "ExtraSet.list_inter")
- end;;
-
-
-let copy_file src dst =
+let copy_file src dst =
let len = 5096 in
let b = Bytes.make len ' ' in
let read_len = ref 0 in
@@ -352,7 +346,7 @@ let move_file src dst =
try
(* try efficient version *)
Sys.rename src dst
- with Sys_error _ ->
+ with Sys_error _ ->
begin
(* OK, do it the the hard way *)
copy_file src dst;
@@ -365,7 +359,7 @@ let same_content_files file1 file2 : bool =
let s1 = Stream.of_channel (open_in_bin file1) in
let s2 = Stream.of_channel (open_in_bin file2) in
let stream_is_empty s = (try Stream.empty s; true with Stream.Failure -> false) in
- try
+ try
while ((Stream.next s1) = (Stream.next s2)) do () done;
false
with Stream.Failure -> stream_is_empty s1 && stream_is_empty s2
@@ -449,9 +443,6 @@ let zencode_string str = "z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.ma
let zencode_upper_string str = "Z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.map zchar (string_to_list str))
-(** Encode string for use as a filename. We can't use zencode directly
- because some operating systems make the mistake of being
- case-insensitive. *)
let file_encode_string str =
let zstr = zencode_string str in
let md5 = Digest.to_hex (Digest.string zstr) in