-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paths1.ml
More file actions
45 lines (40 loc) · 889 Bytes
/
s1.ml
File metadata and controls
45 lines (40 loc) · 889 Bytes
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
43
44
45
open S
open R
module S1 = (struct
type t = bool array
let create n p = Array.make p false
let in_sample t x = t.(x)
let add2_sample t x = t.(x) <- true
let clear_sample t =
let rec loop i =
if i < 0 then ()
else
let () = t.(i) <- false in
loop (i-1)
in
loop (Array.length t -1)
let fill_sample sample n p =
let rec loop i =
if i = 0
then ()
else
let rec find_new () =
let x = random_range p in
if in_sample sample x
then find_new()
else add2_sample sample x
in
let () = find_new () in
loop (i-1)
in
loop n
let iter t f =
let s = Array.length t in
let rec loop i =
if i = s then ()
else
let () = if t.(i) then f i in
loop (i+1)
in
loop 0
end : S)