text stringlengths 12 786k |
|---|
let as_widget o = ( o :> GObj . widget ) |
let main_window ( ) = let logo = GdkPixbuf . from_file ( Filename . concat ! Cfg . datadir " logo . png " ) in let mkbutton ctrl = let label , text = Controls . help ctrl in let btn = GButton . tool_button ~ stock ( : Controls . stock ctrl ) ~ label ( ) in ignore ( btn # ... |
let set_window_title window fmt = Printf . ksprintf ( fun s -> window # set_title ( s ^ " - ocaml - top " ^ Cfg . version ) ) fmt |
let open_text_view buffer = Tools . debug " open text view " ; let view = GSourceView3 . source_view ~ source_buffer : buffer ~ auto_indent : true ~ highlight_current_line : true ~ indent_on_tab : false ~ indent_width : 2 ~ accepts_tab : false ~ wrap_mode ` : CHAR ~ show_right_margin : fa... |
let open_toplevel_view top_buf = Tools . debug " open top view " ; let view = GSourceView3 . source_view ~ source_buffer : top_buf ~ auto_indent : false ~ highlight_current_line : false ~ indent_on_tab : false ~ indent_width : 2 ~ accepts_tab : false ~ wrap_mode ` : NONE ~ cursor_visible ... |
let set_font ( src_view : GSourceView3 . source_view ) ( top_view : GSourceView3 . source_view ) str = let font = GPango . font_description_from_string str in Cfg . font := font # to_string ; src_view # misc # modify_font font ; top_view # misc # modify_font font ; Cfg . char_width :=... |
let switch_fullscreen = let full = ref false in fun window -> if ! full then window # unfullscreen ( ) else window # fullscreen ( ) ; full := not ! full |
module Dialogs = struct type ' a cps = ( ' a -> unit ) -> unit let choose_file ~ parent action ( ? cancel = fun ( ) -> ( ) ) k = let title , button_label = match action with | ` OPEN -> " Please choose file to load " , " Load " | ` SAVE -> " Please choose file to save... |
module Stdlib = struct external register_named_value : string -> ' a -> unit = " caml_register_named_value " external raise : exn -> ' a = " % raise " external raise_notrace : exn -> ' a = " % raise_notrace " let failwith s = raise ( Failure s ) let invalid_arg s = raise ( Invalid... |
type ( ' a , ' b ) t = { mutable size : int ; mutable data : ( ' a , ' b ) bucketlist array ; mutable seed : int ; mutable initial_size : int } | Empty | Cons of { mutable key : ' a ; mutable data : ' b ; mutable next : ( ' a , ' b ) bucketlist } |
let ongoing_traversal h = Obj . size ( Obj . repr ( Sys . opaque_identity h ) ) < 4 || h . initial_size < 0 |
let flip_ongoing_traversal h = h . initial_size <- - h . initial_size |
let filter_map_inplace f htab = let d = htab . data in let old_trav = ongoing_traversal htab in if not old_trav then flip_ongoing_traversal htab ; try for i = 0 to Array . length d - 1 do filter_map_inplace_bucket f htab i Empty htab . data . ( i ) done with exn when not old_trav -> flip_ongoing_t... |
let n0 = Int64 . of_int 0 ; ; |
let n1 = Int64 . of_int 1 ; ; |
let n2 = Int64 . of_int 2 ; ; |
let n3 = Int64 . of_int 3 ; ; |
let n5 = Int64 . of_int 5 ; ; |
let ( % ) = Int64 . rem ; ; |
let ( * ) = Int64 . mul ; ; |
let ( / ) = Int64 . div ; ; |
let ( + ) = Int64 . add ; ; |
let digit = Int64 . of_string " 1000000000000000000 " ; ; |
let mul n ( pl , ph ) = ( ( n * pl ) % digit , n * ph + ( n * pl ) / digit ) ; ; |
let cmp ( nl , nh ) ( pl , ph ) = if nh < ph then - 1 else if nh > ph then 1 else if nl < pl then - 1 else if nl > pl then 1 else 0 ; ; |
let x2 = fun p -> mul n2 p ; ; |
let x3 = fun p -> mul n3 p ; ; |
let x5 = fun p -> mul n5 p ; ; |
let nn1 = ( n1 , n0 ) ; ; |
let pr ( nl , nh ) = if compare nh n0 = 0 then Printf . printf " % Ld \ n " nl else Printf . printf " % Ld % 018Ld \ n " nh nl ; ; |
let nn1 = num_of_int 1 ; ; |
let x2 = fun p -> ( num_of_int 2 ) */ p ; ; |
let x3 = fun p -> ( num_of_int 3 ) */ p ; ; |
let x5 = fun p -> ( num_of_int 5 ) */ p ; ; |
let cmp n p = sign_num ( n -/ p ) ; ; |
let pr n = Printf . printf " % s \ n " ( string_of_num n ) ; ; ) * |
type ' a lcons = Cons of ' a * ' a lcons Lazy . t ; ; |
type ' a llist = ' a lcons Lazy . t ; ; |
let rec map f l = lazy ( match force l with | Cons ( x , ll ) -> Cons ( f x , map f ll ) ) ; ; |
let rec merge cmp l1 l2 = lazy ( match force l1 , force l2 with | Cons ( x1 , ll1 ) , Cons ( x2 , ll2 ) -> let c = cmp x1 x2 in if c = 0 then Cons ( x1 , merge cmp ll1 ll2 ) else if c < 0 then Cons ( x1 , merge cmp ll1 l2 ) else Cons ( x2 , merge cmp l1 ll2 ) ) ; ; |
let rec iter_interval f l ( start , stop ) = if stop = 0 then ( ) else match force l with | Cons ( x , ll ) -> if start <= 0 then f x ; iter_interval f ll ( start - 1 , stop - 1 ) ; ; |
let rec hamming = lazy ( Cons ( nn1 , merge cmp ham2 ( merge cmp ham3 ham5 ) ) ) and ham2 = lazy ( force ( map x2 hamming ) ) and ham3 = lazy ( force ( map x3 hamming ) ) and ham5 = lazy ( force ( map x5 hamming ) ) ; ; |
type ( ' a , ' b ) t = { mutable size : int ; mutable data : ( ' a , ' b ) bucketlist array ; mutable seed : int ; mutable initial_size : int ; } Empty | Cons of { mutable key : ' a ; mutable data : ' b ; mutable next : ( ' a , ' b ) bucketlist } |
let ongoing_traversal h = Obj . size ( Obj . repr h ) < 4 || h . initial_size < 0 |
let flip_ongoing_traversal h = h . initial_size <- - h . initial_size |
let randomized_default = let params = try Sys . getenv " OCAMLRUNPARAM " with Not_found -> try Sys . getenv " CAMLRUNPARAM " with Not_found -> " " in String . contains params ' R ' |
let randomized = ref randomized_default |
let randomize ( ) = randomized := true |
let is_randomized ( ) = ! randomized |
let prng = lazy ( Random . State . make_self_init ( ) ) |
let rec power_2_above x n = if x >= n then x else if x * 2 > Sys . max_array_length then x else power_2_above ( x * 2 ) n |
let create ( ? random = ! randomized ) initial_size = let s = power_2_above 16 initial_size in let seed = if random then Random . State . bits ( Lazy . force prng ) else 0 in { initial_size = s ; size = 0 ; seed = seed ; data = Array . make s Empty } |
let clear h = if h . size > 0 then begin h . size <- 0 ; Array . fill h . data 0 ( Array . length h . data ) Empty end |
let reset h = let len = Array . length h . data in if Obj . size ( Obj . repr h ) < 4 || len = abs h . initial_size then clear h else begin h . size <- 0 ; h . data <- Array . make ( abs h . initial_size ) Empty end |
let copy_bucketlist = function | Empty -> Empty | Cons { key ; data ; next } -> let rec loop prec = function | Empty -> ( ) | Cons { key ; data ; next } -> let r = Cons { key ; data ; next } in begin match prec with | Empty -> assert false | Cons prec -> prec . next <- r en... |
let copy h = { h with data = Array . map copy_bucketlist h . data } |
let length h = h . size |
let insert_all_buckets indexfun inplace odata ndata = let nsize = Array . length ndata in let ndata_tail = Array . make nsize Empty in let rec insert_bucket = function | Empty -> ( ) | Cons { key ; data ; next } as cell -> let cell = if inplace then cell else Cons { key ; data ; next = E... |
let resize indexfun h = let odata = h . data in let osize = Array . length odata in let nsize = osize * 2 in if nsize < Sys . max_array_length then begin let ndata = Array . make nsize Empty in let inplace = not ( ongoing_traversal h ) in h . data <- ndata ; insert_all_buckets ( indexfun h )... |
let iter f h = let rec do_bucket = function | Empty -> ( ) | Cons { key ; data ; next } -> f key data ; do_bucket next in let old_trav = ongoing_traversal h in if not old_trav then flip_ongoing_traversal h ; try let d = h . data in for i = 0 to Array . length d - 1 do do_bucket d . ( ... |
let rec filter_map_inplace_bucket f h i prec = function | Empty -> begin match prec with | Empty -> h . data . ( i ) <- Empty | Cons c -> c . next <- Empty end | ( Cons ( { key ; data ; next } as c ) ) as slot -> begin match f key data with | None -> h . size <- h . size - 1... |
let filter_map_inplace f h = let d = h . data in let old_trav = ongoing_traversal h in if not old_trav then flip_ongoing_traversal h ; try for i = 0 to Array . length d - 1 do filter_map_inplace_bucket f h i Empty h . data . ( i ) done ; if not old_trav then flip_ongoing_traversal h with exn when... |
let fold f h init = let rec do_bucket b accu = match b with Empty -> accu | Cons { key ; data ; next } -> do_bucket next ( f key data accu ) in let old_trav = ongoing_traversal h in if not old_trav then flip_ongoing_traversal h ; try let d = h . data in let accu = ref init in for i = 0 to Arra... |
type statistics = { num_bindings : int ; num_buckets : int ; max_bucket_length : int ; bucket_histogram : int array } |
let rec bucket_length accu = function | Empty -> accu | Cons { next } -> bucket_length ( accu + 1 ) next |
let stats h = let mbl = Array . fold_left ( fun m b -> max m ( bucket_length 0 b ) ) 0 h . data in let histo = Array . make ( mbl + 1 ) 0 in Array . iter ( fun b -> let l = bucket_length 0 b in histo . ( l ) <- histo . ( l ) + 1 ) h . data ; { num_bindings = h .... |
let to_seq tbl = let tbl_data = tbl . data in let rec aux i buck ( ) = match buck with | Empty -> if i = Array . length tbl_data then Seq . Nil else aux ( i + 1 ) tbl_data . ( i ) ( ) | Cons { key ; data ; next } -> Seq . Cons ( ( key , data ) , aux i next ) in au... |
let to_seq_keys m = Seq . map fst ( to_seq m ) |
let to_seq_values m = Seq . map snd ( to_seq m ) |
module type HashedType = sig type t val equal : t -> t -> bool val hash : t -> int end |
module type SeededHashedType = sig type t val equal : t -> t -> bool val hash : int -> t -> int end |
module type S = sig type key type ' ! a t val create : int -> ' a t val clear : ' a t -> unit val reset : ' a t -> unit val copy : ' a t -> ' a t val add : ' a t -> key -> ' a -> unit val remove : ' a t -> key -> unit val find : ' a t -> key -> ' a val find_opt : ' a t -> k... |
module type SeededS = sig type key type ' ! a t val create : ? random : bool -> int -> ' a t val clear : ' a t -> unit val reset : ' a t -> unit val copy : ' a t -> ' a t val add : ' a t -> key -> ' a -> unit val remove : ' a t -> key -> unit val find : ' a t -> key -> ' a v... |
module MakeSeeded ( H : SeededHashedType ) : ( SeededS with type key = H . t ) = struct type key = H . t type ' a hashtbl = ( key , ' a ) t type ' a t = ' a hashtbl let create = create let clear = clear let reset = reset let copy = copy let key_index h key = ( H . hash h . se... |
module Make ( H : HashedType ) : ( S with type key = H . t ) = struct include MakeSeeded ( struct type t = H . t let equal = H . equal let hash ( _seed : int ) x = H . hash x end ) let create sz = create ~ random : false sz let of_seq i = let tbl = create 16 in replace_seq tbl i ;... |
let hash x = seeded_hash_param 10 100 0 x |
let hash_param n1 n2 x = seeded_hash_param n1 n2 0 x |
let seeded_hash seed x = seeded_hash_param 10 100 seed x |
let key_index h key = if Obj . size ( Obj . repr h ) >= 4 then ( seeded_hash_param 10 100 h . seed key ) land ( Array . length h . data - 1 ) else invalid_arg " Hashtbl : unsupported hash table format " |
let add h key data = let i = key_index h key in let bucket = Cons { key ; data ; next = h . data . ( i ) } in h . data . ( i ) <- bucket ; h . size <- h . size + 1 ; if h . size > Array . length h . data lsl 1 then resize key_index h |
let rec remove_bucket h i key prec = function | Empty -> ( ) | ( Cons { key = k ; next } ) as c -> if compare k key = 0 then begin h . size <- h . size - 1 ; match prec with | Empty -> h . data . ( i ) <- next | Cons c -> c . next <- next end else remove_bucket h i key c n... |
let remove h key = let i = key_index h key in remove_bucket h i key Empty h . data . ( i ) |
let rec find_rec key = function | Empty -> raise Not_found | Cons { key = k ; data ; next } -> if compare key k = 0 then data else find_rec key next |
let find h key = match h . data . ( key_index h key ) with | Empty -> raise Not_found | Cons { key = k1 ; data = d1 ; next = next1 } -> if compare key k1 = 0 then d1 else match next1 with | Empty -> raise Not_found | Cons { key = k2 ; data = d2 ; next = next2 } -> if compare key... |
let rec find_rec_opt key = function | Empty -> None | Cons { key = k ; data ; next } -> if compare key k = 0 then Some data else find_rec_opt key next |
let find_opt h key = match h . data . ( key_index h key ) with | Empty -> None | Cons { key = k1 ; data = d1 ; next = next1 } -> if compare key k1 = 0 then Some d1 else match next1 with | Empty -> None | Cons { key = k2 ; data = d2 ; next = next2 } -> if compare key k2 = 0 the... |
let find_all h key = let rec find_in_bucket = function | Empty -> [ ] | Cons { key = k ; data ; next } -> if compare k key = 0 then data :: find_in_bucket next else find_in_bucket next in find_in_bucket h . data . ( key_index h key ) |
let rec replace_bucket key data = function | Empty -> true | Cons ( { key = k ; next } as slot ) -> if compare k key = 0 then ( slot . key <- key ; slot . data <- data ; false ) else replace_bucket key data next |
let replace h key data = let i = key_index h key in let l = h . data . ( i ) in if replace_bucket key data l then begin h . data . ( i ) <- Cons { key ; data ; next = l } ; h . size <- h . size + 1 ; if h . size > Array . length h . data lsl 1 then resize key_index h end |
let mem h key = let rec mem_in_bucket = function | Empty -> false | Cons { key = k ; next } -> compare k key = 0 || mem_in_bucket next in mem_in_bucket h . data . ( key_index h key ) |
let add_seq tbl i = Seq . iter ( fun ( k , v ) -> add tbl k v ) i |
let replace_seq tbl i = Seq . iter ( fun ( k , v ) -> replace tbl k v ) i |
let of_seq i = let tbl = create 16 in replace_seq tbl i ; tbl |
let rebuild ( ? random = ! randomized ) h = let s = power_2_above 16 ( Array . length h . data ) in let seed = if random then Random . State . bits ( Lazy . force prng ) else if Obj . size ( Obj . repr h ) >= 4 then h . seed else 0 in let h ' = { size = h . size ; dat... |
let text = " \ \ n \ USE \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ \ n \ ... |
let make ( type model action state ) driver : ( module S with type model = model and type action = action and type state = state ) = let view_obs = Incr . observe ( Driver . view_incr driver ) in Incr . stabilize ( ) ; ( module struct type nonrec model = model type nonrec action = acti... |
type t = [ ` Hex of string ] |
let invalid_arg fmt = Printf . ksprintf ( fun str -> raise ( Invalid_argument str ) ) fmt |
let hexa = " 0123456789abcdef " " 0000000000000000111111111111111122222222222222223333333333333333 \ 4444444444444444555555555555555566666666666666667777777777777777 \ 88888888888888889999999999999999aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb \ ccccccccccccccccddddddddddddddddeeeeeeeeeeeeeeeeffffffffffffffff " " ... |
let char_is_printable chr = chr >= ' ' && chr <= ' ' ~ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.