package dune-private-libs

  1. Overview
  2. Docs
Private libraries of Dune

Install

Dune Dependency

Authors

Maintainers

Sources

dune-3.18.2.tbz
sha256=56be509ffc3c5ba652113d9e6b43edb04a691f1e1f6cbba17b9d243b1239a7af
sha512=ee04a0c4ab946817018c78cd9b19c8d3082ee3b1cef78c699fff4ea37fd79543823a9751d0b945d2fd1783396ceded045cbec986a85f7a8f7bac93e04650fff3

doc/src/dune-private-libs.dune_re/color_map.ml.html

Source file color_map.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
(* In reality, this can really be represented as a bool array.

   The representation is best thought of as a list of all chars along with a
   flag:

   (a, 0), (b, 1), (c, 0), (d, 0), ...

   characters belonging to the same color are represented by sequnces of
   characters with the flag set to 0.
*)

type t = Bytes.t

let make () = Bytes.make 257 '\000'

let flatten cm =
  let c = Bytes.create 256 in
  let color_repr = Bytes.create 256 in
  let v = ref 0 in
  Bytes.set c 0 '\000';
  Bytes.set color_repr 0 '\000';
  for i = 1 to 255 do
    if Bytes.get cm i <> '\000' then incr v;
    Bytes.set c i (Char.chr !v);
    Bytes.set color_repr !v (Char.chr i)
  done;
  (Bytes.unsafe_to_string c, Bytes.sub_string color_repr 0 (!v + 1), !v + 1)

(* mark all the endpoints of the intervals of the char set with the 1 byte *)
let split s cm =
  Cset.iter s ~f:(fun i j ->
      Bytes.set cm i '\001';
      Bytes.set cm (j + 1) '\001';
    )
OCaml

Innovation. Community. Security.