package bst

  1. Overview
  2. Docs
Bisector tree implementation in OCaml.

Install

Dune Dependency

Authors

Maintainers

Sources

v5.0.0.tar.gz
sha256=175215fc6641864cd4e9a14373b1af185d2b23cf774a3892550f41e7072209a1
md5=2cff1148329e7c3b10cce7ae7728c97b

doc/src/bst/myArray.ml.html

Source file myArray.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
43
44
(* extend stdlib's Array module *)

include Array

(* <=> List.partition *)
let partition p a =
  let n = length a in
  if n = 0 then ([||], [||])
  else
    let ok_count = ref 0 in
    let mask =
      init n (fun i ->
          let pi = p (unsafe_get a i) in
          if pi then incr ok_count;
          pi) in
    let ko_count = n - !ok_count in
    let init = unsafe_get a 0 in
    let ok = make !ok_count init in
    let ko = make ko_count init in
    let j = ref 0 in
    let k = ref 0 in
    for i = 0 to n - 1 do
      let x = unsafe_get a i in
      let px = unsafe_get mask i in
      if px then
        (unsafe_set ok !j x;
         incr j)
      else
        (unsafe_set ko !k x;
         incr k)
    done;
    (ok, ko)

exception Break

(* to compile with versions of the stdlib <= 4.02.3 *)
let for_all p a =
  try
    let n = length a in
    for i = 0 to n - 1 do
      if not (p (unsafe_get a i)) then raise Break
    done;
    true
  with Break -> false
OCaml

Innovation. Community. Security.