package p4spectec
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
P4-SpecTec: A mechanization toolchain for the P4 Programming Language
Install
dune-project
Dependency
Authors
Maintainers
Sources
v0.1.2.tar.gz
md5=1a3bc0a385fe1ecf403c019f49aa6de6
sha512=5d20b5821f33e2a3a5419b208606f27c01511994c2b3b1e1cdf4c077056dfd0aa81682af0720e1060ee2bfb0341918fcc4c53159820205a2bc32b725e5c1a714
doc/src/p4spectec.backend_testgen_neg/rand.ml.html
Source file rand.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42(* Helper for random sampling *) let random_select (lst : 'a list) : 'a option = if List.length lst = 0 then None else Random.int (List.length lst) |> List.nth lst |> Option.some let random_sample (size : int) (lst : 'a list) : 'a list = let arr = Array.of_list lst in let len = Array.length arr in if len <= size then lst else let idxs = Hashtbl.create size in let rec random_sample' lst_sample = if List.length lst_sample = size then lst_sample else let idx = Random.int len in if Hashtbl.mem idxs idx then random_sample' lst_sample else ( Hashtbl.add idxs idx (); random_sample' (arr.(idx) :: lst_sample)) in random_sample' [] let random_sample_weighted (size : int) (probs : float list) (lst : 'a list) : 'a list = List.combine probs lst |> List.filter (fun (p, _) -> Random.float 1.0 < p) |> List.map snd |> random_sample size (* Shuffling a list *) let shuffle (lst : 'a list) : 'a list = let rec shuffle' (lst_shuffled : 'a list) (lst : 'a list) = match lst with | [] -> lst_shuffled | _ -> let idx_pick = Random.int (List.length lst) in let item = List.nth lst idx_pick in let lst = List.filteri (fun idx _ -> idx <> idx_pick) lst in shuffle' (item :: lst_shuffled) lst in shuffle' [] lst
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>