text stringlengths 0 601k |
|---|
let length h = h . size |
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 [ ] in h . data <- ndata ; let rec insert_bucket = function [ ] -> ( ) | key :: rest -> insert_bucket rest ; let nidx = indexfun h key ... |
let key_index h key = if Obj . size ( Obj . repr h ) >= 3 then ( seeded_hash_param 10 100 h . seed key ) land ( Array . length h . data - 1 ) else ( old_hash_param 10 100 key ) mod ( Array . length h . data ) |
let add h key = let i = key_index h key in let bucket = key :: 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 remove h key = let rec remove_bucket = function | [ ] -> [ ] | k :: next -> if compare k key = 0 then begin h . size <- h . size - 1 ; next end else k :: remove_bucket next in let i = key_index h key in h . data . ( i ) <- remove_bucket h . data . ( i ) |
let rec find_rec key = function | [ ] -> raise Not_found | k :: rest -> if compare key k = 0 then k else find_rec key rest |
let find h key = match h . data . ( key_index h key ) with | [ ] -> raise Not_found | k1 :: rest1 -> if compare key k1 = 0 then k1 else match rest1 with | [ ] -> raise Not_found | k2 :: rest2 -> if compare key k2 = 0 then k2 else match rest2 with | [ ] -> raise Not_found | k3 :: rest3 -> if compare key k3 = 0 then k3 e... |
let find_all h key = let rec find_in_bucket = function | [ ] -> [ ] | k :: rest -> if compare k key = 0 then k :: find_in_bucket rest else find_in_bucket rest in find_in_bucket h . data . ( key_index h key ) |
let replace h key = let rec replace_bucket = function | [ ] -> raise Not_found | k :: next -> if compare k key = 0 then k :: next else k :: replace_bucket next in let i = key_index h key in let l = h . data . ( i ) in try h . data . ( i ) <- replace_bucket l with Not_found -> h . data . ( i ) <- key :: l ; h . size <- ... |
let mem h key = let rec mem_in_bucket = function | [ ] -> false | k :: rest -> compare k key = 0 || mem_in_bucket rest in mem_in_bucket h . data . ( key_index h key ) |
let iter f h = let rec do_bucket = function | [ ] -> ( ) | k :: rest -> f k ; do_bucket rest in let d = h . data in for i = 0 to Array . length d - 1 do do_bucket d . ( i ) done |
let fold f h init = let rec do_bucket b accu = match b with [ ] -> accu | k :: rest -> do_bucket rest ( f k accu ) in let d = h . data in let accu = ref init in for i = 0 to Array . length d - 1 do accu := do_bucket d . ( i ) ! accu done ; ! accu |
let find_or_add tbl v = try find tbl v with | Not_found -> add tbl v ; v |
type statistics = { num_bindings : int ; num_buckets : int ; max_bucket_length : int ; bucket_histogram : int array } |
let rec bucket_length accu = function | [ ] -> accu | _ :: rest -> bucket_length ( accu + 1 ) rest |
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 . size ; num_buckets = Array . length h . data ; max_bucket... |
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 t val create : int -> t val clear : t -> unit val reset : t -> unit val copy : t -> t val add : t -> key -> unit val remove : t -> key -> unit val find : t -> key -> key val find_all : t -> key -> key list val replace : t -> key -> unit val mem : t -> key -> bool val iter : ( key -> un... |
module type SeededS = sig type key type t val create : ? random : bool -> int -> t val clear : t -> unit val reset : t -> unit val copy : t -> t val add : t -> key -> unit val remove : t -> key -> unit val find : t -> key -> key val find_all : t -> key -> key list val replace : t -> key -> unit val mem : t -> key -> bo... |
module MakeSeeded ( H : SeededHashedType ) : ( SeededS with type key = H . t ) = struct type key = H . t type hashtbl = key t type t = hashtbl let create = create let clear = clear let reset = reset let copy = copy let key_index h key = ( H . hash h . seed key ) land ( Array . length h . data - 1 ) let add h key = let ... |
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 end |
int -> int -> int -> ' a -> int = " caml_hash " " noalloc " int -> int -> ' a -> int = " caml_hash_univ_param " " noalloc " |
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 |
type ( ' a , ' b ) t = { mutable size : int ; mutable data : ( ' a , ' b ) bucketlist array ; mutable seed : int ; initial_size : int ; } Empty | Cons of ' a * ' b * ( ' a , ' b ) bucketlist |
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 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 = h . size <- 0 ; let len = Array . length h . data in for i = 0 to len - 1 do h . data . ( i ) <- Empty done |
let reset h = let len = Array . length h . data in if Obj . size ( Obj . repr h ) < 4 || len = h . initial_size then clear h else begin h . size <- 0 ; h . data <- Array . make h . initial_size Empty end |
let copy h = { h with data = Array . copy h . data } |
let length h = h . size |
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 h . data <- ndata ; let rec insert_bucket = function Empty -> ( ) | Cons ( key , data , rest ) -> insert_bucket rest ; let nid... |
let key_index h key = if Obj . size ( Obj . repr h ) >= 3 then ( seeded_hash_param 10 100 h . seed key ) land ( Array . length h . data - 1 ) else ( old_hash_param 10 100 key ) mod ( Array . length h . data ) |
let add h key info = let i = key_index h key in let bucket = Cons ( key , info , a_get h . data i ) in a_set h . data i bucket ; h . size <- h . size + 1 ; if h . size > Array . length h . data lsl 1 then resize key_index h |
let remove h key = let rec remove_bucket = function | Empty -> Empty | Cons ( k , i , next ) -> if compare k key = 0 then begin h . size <- h . size - 1 ; next end else Cons ( k , i , remove_bucket next ) in let i = key_index h key in a_set h . data i @@ remove_bucket @@ a_get h . data i |
let rec find_rec key = function | Empty -> raise Not_found | Cons ( k , d , rest ) -> if compare key k = 0 then d else find_rec key rest |
let find h key = match a_get h . data @@ key_index h key with | Empty -> raise Not_found | Cons ( k1 , d1 , rest1 ) -> if compare key k1 = 0 then d1 else match rest1 with | Empty -> raise Not_found | Cons ( k2 , d2 , rest2 ) -> if compare key k2 = 0 then d2 else match rest2 with | Empty -> raise Not_found | Cons ( k3 ,... |
let find_all h key = let rec find_in_bucket = function | Empty -> [ ] | Cons ( k , d , rest ) -> if compare k key = 0 then d :: find_in_bucket rest else find_in_bucket rest in find_in_bucket @@ a_get h . data @@ key_index h key |
let replace h key info = let rec replace_bucket = function | Empty -> raise Not_found | Cons ( k , i , next ) -> if compare k key = 0 then Cons ( key , info , next ) else Cons ( k , i , replace_bucket next ) in let i = key_index h key in let l = a_get h . data i in try a_set h . data i @@ replace_bucket l with Not_foun... |
let mem h key = let rec mem_in_bucket = function | Empty -> false | Cons ( k , _d , rest ) -> compare k key = 0 || mem_in_bucket rest in mem_in_bucket @@ a_get h . data @@ key_index h key |
let iter f h = let rec do_bucket = function | Empty -> ( ) | Cons ( k , d , rest ) -> f k d ; do_bucket rest in let d = h . data in for i = 0 to Array . length d - 1 do do_bucket @@ a_get d i done |
let fold f h init = let rec do_bucket b accu = match b with Empty -> accu | Cons ( k , d , rest ) -> do_bucket rest ( f k d accu ) in let d = h . data in let accu = ref init in for i = 0 to Array . length d - 1 do accu := do_bucket ( a_get d i ) ! accu done ; ! accu |
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 ( _ , _ , rest ) -> bucket_length ( accu + 1 ) rest |
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 a_set histo l @@ a_get histo l + 1 ) h . data ; { num_bindings = h . size ; num_buckets = Array . length h . data ; max_bucket... |
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_all : ' a t -> key -> ' a list val replace : ' a t -> key -> ' a... |
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 val find_all : ' a t -> key -> ' a list val repl... |
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 . seed key ) land ( Array . length h . data - 1 ... |
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 end |
module type S = sig open Signal . Types val lut : int64 -> signal -> signal val muxcy : signal -> signal -> signal -> signal val inv : signal -> signal val xorcy : signal -> signal -> signal val muxf5 : signal -> signal -> signal -> signal val muxf6 : signal -> signal -> signal -> signal val muxf7 : signal -> signal ->... |
module LutEqn = struct type t = | Gnd | Vdd | Input of int64 | And of t * t | Or of t * t | Xor of t * t | Not of t let i0 = Input ( 0L ) let i1 = Input ( 1L ) let i2 = Input ( 2L ) let i3 = Input ( 3L ) let i4 = Input ( 4L ) let i5 = Input ( 5L ) let gnd = Gnd let vdd = Vdd let ( ) &: a b = And ( a , b ) let ( ) |: a ... |
module HardCaml_api = struct open Signal . Types open Signal . Comb open Signal . Seq let lut v sel = let n = 1 lsl ( width sel ) in let rec build i = if i = n then [ ] else let d = if Int64 . logand v ( Int64 . shift_left 1L i ) <> 0L then vdd else gnd in d :: build ( i + 1 ) in mux sel ( build 0 ) let muxcy ci di sel... |
module Unisim = struct open Utils open Signal . Types open Signal . Comb open Signal . Instantiation module B = Bits . Comb . IntbitsList let inv a = ( inst " INV " [ ] [ " I " , a ] [ " O " , 1 ] ) # o " O " let lut v sel = let w = width sel in let w ' = string_of_int w in let init = ( Int64 . to_string v ) |> B . con... |
module type T = sig open Signal . Types val x_lut : LutEqn . t -> signal -> signal val x_map : LutEqn . t -> signal list -> signal val x_and : signal -> signal -> signal val x_or : signal -> signal -> signal val x_xor : signal -> signal -> signal val x_not : signal -> signal val x_reduce_carry : bool -> ( LutEqn . t ->... |
module type LutSize = sig val max_lut : int end |
module Lut4 = struct let max_lut = 4 end |
module Lut6 = struct let max_lut = 6 end |
module XMake ( X : S ) ( L : LutSize ) = struct open Utils open Signal . Types module S = Signal . Comb open S open LutEqn open L let x_lut f s = let i = eval ( width s ) f in X . lut i s let x_map f l = let w = List . hd l |> width in let lut n = x_lut f ( List . map ( fun s -> select s n n ) l |> List . rev |> concat... |
module XComb ( Synth : T ) = struct open Signal . Types include Signal . Base let ( ) &: = Synth . x_and let ( ) |: = Synth . x_or let ( ) ^: = Synth . x_xor let ( ) ~: = Synth . x_not let ( ) +: = Synth . x_add let ( ) -: = Synth . x_sub let ( ) ==: = Synth . x_eq let ( ) <: = Synth . x_lt let ( *: ) = Synth . x_mulu ... |
module XSynthesizeComb ( X : S ) ( L : LutSize ) = Transform . MakeCombTransform ( XComb ( XMake ( X ) ( L ) ) ) |
module XSynthesize ( X : S ) ( L : LutSize ) = open Signal . Types open Signal . Comb open Utils module C = Comb . Make ( XComb ( XMake ( X ) ( L ) ) ) open C module T = Transform . MakeCombTransform ( C ) let transform find signal = match signal with | Signal_reg ( id , r ) -> let r = { r with reg_clock = ( find << ui... |
let debug fmt = Logging . debug " xenstored " fmt |
let info fmt = Logging . info " xenstored " fmt |
let error fmt = Logging . error " xenstored " fmt |
module type DB_S = Irmin . S with type key = Irmin . Contents . String . Path . t and type value = string |
let make ( ? prefer_merge = true ) config db_m = let module DB = ( val db_m : DB_S ) in DB . Repo . create config >>= fun repo -> DB . master Irmin_unix . task repo >>= fun db -> let module DB_View = Irmin . View ( DB ) in let module V = struct type t = { v : DB_View . t ; } let remove_suffix suffix x = let suffix ' = ... |
type bare_jid = string * string [ @@ deriving sexp ] sexp |
type full_jid = bare_jid * string [ @@ deriving sexp ] sexp |
type t = [ | ` Full of full_jid | ` Bare of bare_jid |
let t_to_bare = function | ` Full ( b , _ ) _ -> b | ` Bare b -> b |
let resource = function | ` Full ( _ , r ) r -> Some r | ` Bare _ -> None |
let bare_jid_to_string ( u , d ) d = u ^ " " @ ^ d |
let full_jid_to_string ( b , r ) r = bare_jid_to_string b ^ " " / ^ r |
let jid_to_string = function | ` Full full -> full_jid_to_string full | ` Bare bare -> bare_jid_to_string bare |
let string_to_jid_helper s = let s = Utils . validate_utf8 s in match Astring . String . cut ~ sep " " :@ s with | None -> None | Some ( _ , rest ) rest when rest = " " -> None | Some ( user , rest ) rest -> match Astring . String . cut ~ sep " " :/ rest with | None -> Some ( user , rest , None ) None | Some ( domain ,... |
let string_to_bare_jid s = match string_to_jid_helper s with | Some ( u , d , _ ) _ -> Some ( u , d ) d | None -> None |
let string_to_full_jid s = match string_to_jid_helper s with | Some ( u , d , Some r ) r -> Some ( ( u , d ) d , r ) r | _ -> None |
let string_to_jid s = match string_to_jid_helper s with | Some ( u , d , Some r ) r -> Some ( ` Full ( ( u , d ) d , r ) r ) r | Some ( u , d , None ) None -> Some ( ` Bare ( u , d ) d ) d | None -> None |
let bare_jid_equal ( u , d ) d ( u ' , d ' ) d ' = u = u ' && d = d ' |
let compare_bare_jid ( u , d ) d ( u ' , d ' ) d ' = match compare u u ' with | 0 -> compare d d ' | x -> x |
let hex_chars start s = let hex_char = function | ' a ' . . ' f ' | ' A ' . . ' F ' | ' 0 ' . . ' 9 ' -> true | _ -> false in let rec go idx s = if idx < String . length s then if hex_char ( String . get s idx ) idx then go ( succ idx ) idx s else false else true in go start s |
let is_uuid s = let open String in length s = 36 && hex_chars 0 ( sub s 0 8 ) 8 && get s 8 = ' - ' && hex_chars 0 ( sub s 9 4 ) 4 && get s 13 = ' - ' && hex_chars 0 ( sub s 14 4 ) 4 && get s 18 = ' - ' && hex_chars 0 ( sub s 19 4 ) 4 && get s 23 = ' - ' && hex_chars 0 ( sub s 24 12 ) 12 |
let resource_similar a b = let alen = String . length a and blen = String . length b in if abs ( alen - blen ) blen > 4 then false else if is_uuid a && is_uuid b then true else let stop = min alen blen in let rec equal idx = if idx < stop then if String . get a idx = String . get b idx then equal ( succ idx ) idx else ... |
let jid_matches jid jid ' = match jid , jid ' with | ` Bare bare , ` Bare bare ' -> bare_jid_equal bare bare ' | ` Bare bare , ` Full ( bare ' , _ ) _ -> bare_jid_equal bare bare ' | ` Full ( bare , resource ) resource , ` Full ( bare ' , resource ' ) resource ' -> bare_jid_equal bare bare ' && resource = resource ' | ... |
let xmpp_jid_to_jid jid = let { JID . lnode ; JID . ldomain ; JID . lresource ; _ } = jid in let lnode = Utils . validate_utf8 lnode and ldomain = Utils . validate_utf8 ldomain and lresource = Utils . validate_utf8 lresource in let bare = ( lnode , ldomain ) ldomain in if lresource = " " then ` Bare bare else ` Full ( ... |
let jid_to_xmpp_jid jid = JID . of_string ( jid_to_string jid ) jid |
type t = { pos : string * Xmlm . pos ; name : Xmlm . name ; mutable attrs : Xmlm . attribute list ; mutable children : tree list ; } |
let pp f node = let file , ( line , col ) = node . pos in Fmt . pf f " <% a > at % s :% d :% d " Xmlm . pp_name node . name file line col |
let check_empty node = node . attrs |> List . iter ( function | ( ( " " , name ) , _ ) -> Fmt . failwith " Unexpected attribute % S in % a " name pp node | _ -> ( ) ) ; node . children |> List . iter ( function | E ( { name = ( " " , _ ) ; _ } as n ) -> Fmt . failwith " Unexpected element % a " pp n | D d when String .... |
let take_elements name node f = let name = ( " " , name ) in let rec aux = function | [ ] -> [ ] , [ ] | E e :: xs when e . name = name -> let es , xs = aux xs in ( e :: es ) , xs | n :: xs -> let es , xs = aux xs in es , ( n :: xs ) in let chosen , rest = aux node . children in node . children <- rest ; chosen |> List... |
let take_sole_opt name node f = match take_elements name node f with | [ ] -> None | [ x ] -> Some x | _ -> Fmt . failwith " Multiple % S children in % a " ! name pp node |
let take_sole name node f = match take_sole_opt name node f with | Some x -> x | None -> Fmt . failwith " No % S child in % a " ! name pp node |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.