text stringlengths 0 601k |
|---|
module BaseCompat = struct module Compat_0_4 = struct let rctxt = ref ! BaseContext . default module BaseSetup = struct module Original = BaseSetup open OASISTypes type std_args_fun = package -> string array -> unit type ( ' a , ' b ) section_args_fun = name * ( package -> ( common_section * ' a ) -> string array -> ' ... |
module InternalConfigurePlugin = struct open BaseEnv open OASISTypes open OASISUtils open OASISGettext open BaseMessage let configure ~ ctxt : _ pkg argv = let var_ignore_eval var = let _s : string = var ( ) in ( ) in let errors = ref SetString . empty in let buff = Buffer . create 13 in let add_errors fmt = Printf . k... |
module InternalInstallPlugin = struct open BaseEnv open BaseStandardVar open BaseMessage open OASISTypes open OASISFindlib open OASISGettext open OASISUtils let exec_hook = ref ( fun ( cs , bs , exec ) -> cs , bs , exec ) let lib_hook = ref ( fun ( cs , bs , dn , lib ) -> cs , bs , dn , lib , [ ] ) let obj_hook = ref (... |
module OCamlbuildCommon = struct open OASISGettext open BaseEnv open BaseStandardVar open OASISTypes type extra_args = string list let ocamlbuild_clean_ev = " ocamlbuild - clean " let ocamlbuildflags = var_define ~ short_desc ( : fun ( ) -> " OCamlbuild additional flags " ) " ocamlbuildflags " ( fun ( ) -> " " ) let fi... |
module OCamlbuildPlugin = struct open OASISTypes open OASISGettext open OASISUtils open OASISString open BaseEnv open OCamlbuildCommon open BaseStandardVar let cond_targets_hook = ref ( fun lst -> lst ) let build ~ ctxt extra_args pkg argv = let in_build_dir fn = Filename . concat ( build_dir argv ) fn in let in_build_... |
module OCamlbuildDocPlugin = struct open OASISTypes open OASISGettext open OCamlbuildCommon type run_t = { extra_args : string list ; run_path : unix_filename ; } let doc_build ~ ctxt run _ ( cs , _ ) argv = let index_html = OASISUnixPath . make [ run . run_path ; cs . cs_name " . ^ docdir " ; " index . html " ; ] in l... |
let setup_t = { BaseSetup . configure = InternalConfigurePlugin . configure ; build = OCamlbuildPlugin . build [ ] ; test = [ ] ; doc = [ ] ; install = InternalInstallPlugin . install ; uninstall = InternalInstallPlugin . uninstall ; clean = [ OCamlbuildPlugin . clean ] ; clean_test = [ ] ; clean_doc = [ ] ; distclean ... |
let setup ( ) = BaseSetup . setup setup_t ; ; |
let setup_t = BaseCompat . Compat_0_3 . adapt_setup_t setup_t |
let ( ) = setup ( ) ; ; |
let main ~ ctxt ( replace_sections , remove ) oasis_fn pkg = BaseGenerate . restore ~ ctxt ( ) ; if replace_sections then begin let ctxt , _ = BaseSetup . of_package ~ oasis_fn ~ setup_update : false OASISSetupUpdate . NoUpdate pkg in OASISFileTemplate . fold ( fun tmpl ( ) -> match tmpl . body with | Body _ | BodyWith... |
let ( ) = CLISubCommand . register " setup - clean " ( ns_ " Clean all template files from their content " ) CLIData . setup_clean_mkd ( CLICommon . parse_oasis_fn ( CLISubCommand . make_run ( fun ( ) -> let replace_sections = ref false in let remove = ref false in ( [ " - replace - sections " , Arg . Set replace_secti... |
module U = struct let string_of_list f l = " [ " ^ List . fold_left ( fun a b -> a ^ ( f b ) ^ " ; " ) " " l ^ " ] " let print_header h = Printf . printf " % s " ( " \ n " ^ h ^ " \ n " ) |
let _ = U . print_header " Set - AVL tree " ; |
let module MkConfig ( Vars : sig val root : string end ) : Imap_avl . Config = struct let root = Vars . root let shared = " / tmp / repos / shared . git " let init ( ) = let _ = Sys . command ( Printf . sprintf " rm - rf % s " root ) in let _ = Sys . command ( Printf . sprintf " mkdir - p % s " root ) in ( ) |
let module IntAtom = struct type t = int64 let compare = Pervasives . compare let t = Irmin . Type . int64 let resolve x y = x + y let merge3 ~ ancestor x y = ancestor + ( x - ancestor ) + ( y - ancestor ) let equal x y = Pervasives . compare x y = 0 let to_string = Int64 . to_string let of_string = Int64 . of_string l... |
let module CInit = MkConfig ( struct let root = " / tmp / repos / init . git " end ) in |
let module MInit = Imap_avl . MakeVersioned ( CInit ) ( StringKey ) ( IntAtom ) in |
let module M = Mmap_avltree . Make ( StringKey ) ( IntAtom ) in |
let module Vpst = MInit . Vpst in |
let ( ) >>= = Vpst . bind in |
let thread2_f : unit Vpst . t = Vpst . get_latest_version ( ) >>= fun c0 -> let c0 ' = c0 |> ( MInit . OM . add " A " ( Int64 . of_int 40 ) ) |> ( MInit . OM . add " D " ( Int64 . of_int 60 ) ) in Vpst . sync_next_version ~ v : c0 ' >>= fun c1 -> Vpst . liftLwt @@ Lwt_unix . sleep 0 . 5 >>= fun ( ) -> let c1 ' = c1 |> ... |
type ' a t0 = | Empty | Leaf of ' a | Node of { l : ' a t0 ; v : ' a ; r : ' a t0 ; h : int } |
type ' a partial_node = { l : ' a t0 ; v : ' a ; r : ' a t0 ; h : int } |
let [ @ inline ] height = function | Empty -> 0 | Leaf _ -> 1 | Node { h } -> h |
let [ @ inline ] calc_height a b = ( if a >= b then a else b ) + 1 |
let [ @ inline ] unsafe_node v l r h = Node { l ; v ; r ; h } |
let [ @ inline ] unsafe_node_maybe_leaf v l r h = if h = 1 then Leaf v else Node { l ; v ; r ; h } |
let [ @ inline ] singleton x = Leaf x |
let [ @ inline ] unsafe_two_elements x v = unsafe_node v ( singleton x ) empty 2 |
type ' a t = ' a t0 = private | Empty | Leaf of ' a | Node of { l : ' a t0 ; v : ' a ; r : ' a t0 ; h : int } |
let rec min_exn = function | Empty -> raise Not_found | Leaf v -> v | Node { l ; v } -> match l with | Empty -> v | Leaf _ | Node _ -> min_exn l |
let [ @ inline ] is_empty = function Empty -> true | _ -> false |
let rec cardinal_aux acc = function | Empty -> acc | Leaf _ -> acc + 1 | Node { l ; r } -> cardinal_aux ( cardinal_aux ( acc + 1 ) r ) l |
let cardinal s = cardinal_aux 0 s |
let rec elements_aux accu = function | Empty -> accu | Leaf v -> v :: accu | Node { l ; v ; r } -> elements_aux ( v :: elements_aux accu r ) l |
let elements s = elements_aux [ ] s |
let rec iter x f = match x with | Empty -> ( ) | Leaf v -> f v | Node { l ; v ; r } -> iter l f ; f v ; iter r f |
let rec fold s accu f = match s with | Empty -> accu | Leaf v -> f v accu | Node { l ; v ; r } -> fold r ( f v ( fold l accu f ) ) f |
let rec for_all x p = match x with | Empty -> true | Leaf v -> p v | Node { l ; v ; r } -> p v && for_all l p && for_all r p |
let rec exists x p = match x with | Empty -> false | Leaf v -> p v | Node { l ; v ; r } -> p v || exists l p || exists r p |
let rec check_height_and_diff = function | Empty -> 0 | Leaf _ -> 1 | Node { l ; r ; h } -> let hl = check_height_and_diff l in let hr = check_height_and_diff r in if h <> calc_height hl hr then raise Height_invariant_broken else let diff = ( abs ( hl - hr ) ) in if diff > 2 then raise Height_diff_borken else h |
let check tree = ignore ( check_height_and_diff tree ) |
let bal l v r : _ t = let hl = height l in let hr = height r in if hl > hr + 2 then let { l = ll ; r = lr ; v = lv ; h = _ } = ~! l in let hll = height ll in let hlr = height lr in if hll >= hlr then let hnode = calc_height hlr hr in unsafe_node lv ll ( unsafe_node_maybe_leaf v lr r hnode ) ( calc_height hll hnode ) el... |
let rec remove_min_elt = function Empty -> invalid_arg " Set . remove_min_elt " | Leaf _ -> empty | Node { l = Empty ; r } -> r | Node { l ; v ; r } -> bal ( remove_min_elt l ) v r |
let internal_merge l r = match ( l , r ) with | ( Empty , t ) -> t | ( t , Empty ) -> t | ( _ , _ ) -> bal l ( min_exn r ) ( remove_min_elt r ) |
let rec add_min v = function | Empty -> singleton v | Leaf x -> unsafe_two_elements v x | Node n -> bal ( add_min v n . l ) n . v n . r |
let rec add_max v = function | Empty -> singleton v | Leaf x -> unsafe_two_elements x v | Node n -> bal n . l n . v ( add_max v n . r ) |
let rec internal_join l v r = match ( l , r ) with ( Empty , _ ) -> add_min v r | ( _ , Empty ) -> add_max v l | Leaf lv , Node { h = rh } -> if rh > 3 then add_min lv ( add_min v r ) else unsafe_node v l r ( rh + 1 ) | Leaf _ , Leaf _ -> unsafe_node v l r 2 | Node { h = lh } , Leaf rv -> if lh > 3 then add_max rv ( ad... |
let internal_concat t1 t2 = match ( t1 , t2 ) with | ( Empty , t ) -> t | ( t , Empty ) -> t | ( _ , _ ) -> internal_join t1 ( min_exn t2 ) ( remove_min_elt t2 ) |
let rec partition x p = match x with | Empty -> ( empty , empty ) | Leaf v -> let pv = p v in if pv then x , empty else empty , x | Node { l ; v ; r } -> let ( lt , lf ) = partition l p in let pv = p v in let ( rt , rf ) = partition r p in if pv then ( internal_join lt v rt , internal_concat lf rf ) else ( internal_con... |
let of_sorted_array l = let rec sub start n l = if n = 0 then empty else if n = 1 then let x0 = Array . unsafe_get l start in singleton x0 else if n = 2 then let x0 = Array . unsafe_get l start in let x1 = Array . unsafe_get l ( start + 1 ) in unsafe_node x1 ( singleton x0 ) empty 2 else if n = 3 then let x0 = Array . ... |
let is_ordered ~ cmp tree = let rec is_ordered_min_max tree = match tree with | Empty -> ` Empty | Leaf v -> ` V ( v , v ) | Node { l ; v ; r } -> begin match is_ordered_min_max l with | ` No -> ` No | ` Empty -> begin match is_ordered_min_max r with | ` No -> ` No | ` Empty -> ` V ( v , v ) | ` V ( l , r ) -> if cmp v... |
let invariant ~ cmp t = check t ; is_ordered ~ cmp t |
module type S = sig type elt type t val empty : t val is_empty : t -> bool val iter : t -> ( elt -> unit ) -> unit val fold : t -> ' a -> ( elt -> ' a -> ' a ) -> ' a val for_all : t -> ( elt -> bool ) -> bool val exists : t -> ( elt -> bool ) -> bool val singleton : elt -> t val cardinal : t -> int val elements : t ->... |
module type ATOM = sig type t val t : t Irmin . Type . t val compare : t -> t -> int val to_string : t -> string val of_string : string -> t end |
module Make ( Atom : ATOM ) = struct type atom = Atom . t [ @@ derive ezjsonm ] type node = { l : t ; v : Atom . t ; r : t ; h : int64 } and t = | Empty | Node of node [ @@ derive versioned ] let height = function | Empty -> Int64 . of_int 0 | Node { h ; _ } -> h let create l v r = let hl = match l with | Empty -> Int6... |
type ( ' a , ' id ) ' id t0 = ( ' a , ' id ) ' id Set_gen . t0 = | Empty | Node of ( ' a , ' id ) ' id t0 * ' a * ( ' a , ' id ) ' id t0 * int |
type ( ' a , ' id ) ' id enumeration0 = ( ' a , ' id ) ' id Set_gen . enumeration0 = | End | More of ' a * ( ' a , ' id ) ' id t0 * ( ' a , ' id ) ' id enumeration0 |
type t = ( elt , unit ) unit t0 |
type enumeration = ( elt , unit ) unit Set_gen . enumeration0 |
let rec split x ( tree : t ) t : t * bool * t = match tree with | Empty -> ( Empty , false , Empty ) Empty | Node ( Nodel , v , r , _ ) _ -> let c = compare_elt x v in if c = 0 then ( l , true , r ) r else if c < 0 then let ( ll , pres , rl ) rl = split x l in ( ll , pres , Set_gen . internal_join rl v r ) r else let (... |
let rec add x ( tree : t ) t : t = match tree with | Empty -> Node ( NodeEmpty , x , Empty , 1 ) 1 | Node ( Nodel , v , r , _ ) _ as t -> let c = compare_elt x v in if c = 0 then t else if c < 0 then Set_gen . internal_bal ( add x l ) l v r else Set_gen . internal_bal l v ( add x r ) r |
let rec union ( s1 : t ) t ( s2 : t ) t : t = match ( s1 , s2 ) s2 with | ( Empty , t2 ) t2 -> t2 | ( t1 , Empty ) Empty -> t1 | ( Node ( Nodel1 , v1 , r1 , h1 ) h1 , Node ( Nodel2 , v2 , r2 , h2 ) h2 ) h2 -> if h1 >= h2 then if h2 = 1 then add v2 s1 else begin let ( l2 , _ , r2 ) r2 = split v1 s2 in Set_gen . internal... |
let rec inter ( s1 : t ) t ( s2 : t ) t : t = match ( s1 , s2 ) s2 with | ( Empty , t2 ) t2 -> Empty | ( t1 , Empty ) Empty -> Empty | ( Node ( Nodel1 , v1 , r1 , _ ) _ , t2 ) t2 -> begin match split v1 t2 with | ( l2 , false , r2 ) r2 -> Set_gen . internal_concat ( inter l1 l2 ) l2 ( inter r1 r2 ) r2 | ( l2 , true , r... |
let rec diff ( s1 : t ) t ( s2 : t ) t : t = match ( s1 , s2 ) s2 with | ( Empty , t2 ) t2 -> Empty | ( t1 , Empty ) Empty -> t1 | ( Node ( Nodel1 , v1 , r1 , _ ) _ , t2 ) t2 -> begin match split v1 t2 with | ( l2 , false , r2 ) r2 -> Set_gen . internal_join ( diff l1 l2 ) l2 v1 ( diff r1 r2 ) r2 | ( l2 , true , r2 ) r... |
let rec mem x ( tree : t ) t = match tree with | Empty -> false | Node ( Nodel , v , r , _ ) _ -> let c = compare_elt x v in c = 0 || mem x ( if c < 0 then l else r ) r |
let rec remove x ( tree : t ) t : t = match tree with | Empty -> Empty | Node ( Nodel , v , r , _ ) _ -> let c = compare_elt x v in if c = 0 then Set_gen . internal_merge l r else if c < 0 then Set_gen . internal_bal ( remove x l ) l v r else Set_gen . internal_bal l v ( remove x r ) r |
let compare s1 s2 = Set_gen . compare ~ cmp : compare_elt s1 s2 |
let equal s1 s2 = compare s1 s2 = 0 |
let rec subset ( s1 : t ) t ( s2 : t ) t = match ( s1 , s2 ) s2 with | Empty , _ -> true | _ , Empty -> false | Node ( l1 , v1 , r1 , _ ) _ , ( Node ( l2 , v2 , r2 , _ ) _ as t2 ) t2 -> let c = compare_elt v1 v2 in if c = 0 then subset l1 l2 && subset r1 r2 else if c < 0 then subset ( Node ( l1 , v1 , Empty , 0 ) 0 ) 0... |
let rec find x ( tree : t ) t = match tree with | Empty -> raise Not_found | Node ( Nodel , v , r , _ ) _ -> let c = compare_elt x v in if c = 0 then v else find x ( if c < 0 then l else r ) r |
let of_list l = match l with | [ ] -> empty | [ x0 ] x0 -> singleton x0 | [ x0 ; x1 ] x1 -> add x1 ( singleton x0 ) x0 | [ x0 ; x1 ; x2 ] x2 -> add x2 ( add x1 ( singleton x0 ) x0 ) x0 | [ x0 ; x1 ; x2 ; x3 ] x3 -> add x3 ( add x2 ( add x1 ( singleton x0 ) x0 ) x0 ) x0 | [ x0 ; x1 ; x2 ; x3 ; x4 ] x4 -> add x4 ( add x3... |
let of_array l = Array . fold_left ( fun acc x -> add x acc ) acc empty l |
let invariant t = Set_gen . check t ; Set_gen . is_ordered ~ cmp : compare_elt t |
let print fmt s = Format . fprintf fmt [ " @< v { >% a } a ] . " @@ ( fun fmt s -> iter ( fun e -> Format . fprintf fmt [ " @< v >% a ] , @@ " print_elt e ) e s ) s |
module type S = sig type elt type t type ' a map val empty : t val is_empty : t -> bool val mem : t -> elt -> bool val add : t -> elt -> t val singleton : elt -> t val remove : t -> elt -> t val union : t -> t -> t val inter : t -> t -> t val diff : t -> t -> t val compare : t -> t -> Ordering . t val equal : t -> t ->... |
module Stable = struct open Stable_internal module T = struct type ' a t = { mutable value : ' a option ; mutable set_at : Source_code_position . Stable . V1 . t } [ @@ deriving fields ] end module V1 = struct module Format = struct type ' a t = ' a option ref [ @@ deriving bin_io , sexp ] end module T = struct type ' ... |
type ' a t = ' a Stable . T . t |
let sexp_of_t sexp_of_a { value ; set_at } = match value with | None -> [ % message " unset " ] | Some value -> [ % message " " ( value : a ) ~ set_at ( : set_at |> Source_code_position . to_string ) ] ; ; |
let invariant invariant_a t = match t . value with | None -> ( ) | Some a -> invariant_a a ; ; |
let create ( ) = { value = None ; set_at = [ % here ] } |
let set_internal t here value = t . value <- Some value ; t . set_at <- here ; ; |
let set_if_none t here value = if Option . is_none t . value then set_internal t here value |
let set t here value = if Option . is_none t . value then ( set_internal t here value ; Ok ( ) ) else Or_error . error_s [ % message " [ Set_once . set_exn ] already set " ~ setting_at ( : here : Source_code_position . t ) ~ previously_set_at ( : t . set_at : Source_code_position . t ) ] ; ; |
let set_exn t here value = Or_error . ok_exn ( set t here value ) |
let get t = t . value |
let get_exn ( t : _ t ) here = match t . value with | Some a -> a | None -> raise_s [ % message " [ Set_once . get_exn ] unset " ~ at ( : here : Source_code_position . t ) ] ; ; |
let is_none t = Option . is_none t . value |
let is_some t = Option . is_some t . value |
let iter t ~ f = Option . iter t . value ~ f |
module Optional_syntax = struct module Optional_syntax = struct let is_none = is_none let unsafe_value t = get_exn t [ % here ] end end |
type t = | Atom of string | List of t list |
let rec to_string = function | Atom s -> Escape . quote_if_needed s | List l -> Printf . sprintf " ( % s ) " ( List . map ~ f : to_string l |> String . concat ~ sep " : " ) |
let rec pp ppf = function | Atom s -> Format . pp_print_string ppf ( Escape . quote_if_needed s ) | List [ ] -> Format . pp_print_string ppf " ( ) " | List ( first :: rest ) -> Format . pp_open_box ppf 1 ; Format . pp_print_string ppf " ( " ; Format . pp_open_hvbox ppf 0 ; pp ppf first ; List . iter rest ~ f ( : fun se... |
let string_equal ( x : string ) ( y : string ) = x = y |
let rec equal x y = match ( x , y ) with | Atom x , Atom y -> string_equal x y | List x , List y -> equal_list x y | _ , _ -> false match ( xs , ys ) with | [ ] , [ ] -> true | x :: xs , y :: ys -> equal x y && equal_list xs ys | _ , _ -> false |
let compare x y = Ordering . of_int ( compare x y ) |
let rec of_dyn : Dyn . t -> t = function | Opaque -> Atom " < opaque " > | Unit -> List [ ] | Int i -> Atom ( string_of_int i ) | Int64 i -> Atom ( Int64 . to_string i ) | Bool b -> Atom ( string_of_bool b ) | String s -> Atom s | Bytes s -> Atom ( Bytes . to_string s ) | Char c -> Atom ( String . make 1 c ) | Float f ... |
module Stable = struct module Of_sexpable = struct module V1 ( Sexpable : S ) ( M : sig type t val to_sexpable : t -> Sexpable . t val of_sexpable : Sexpable . t -> t end ) : S with type t := M . t = struct let t_of_sexp sexp = let s = Sexpable . t_of_sexp sexp in try M . of_sexpable s with | exn -> of_sexp_error_exn e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.