package riot

  1. Overview
  2. Docs
An actor-model multi-core scheduler for OCaml 5

Install

Dune Dependency

Authors

Maintainers

Sources

riot-0.0.5.tbz
sha256=01b7b82ccc656b12b7315960d9df17eb4682b8f1af68e9fee33171fee1f9cf88
sha512=d8831d8a75fe43a7e8d16d2c0bb7d27f6d975133e17c5dd89ef7e575039c59d27c1ab74fbadcca81ddfbc0c74d1e46c35baba35ef825b36ac6c4e49d7a41d0c2

doc/src/riot.util/dashmap.ml.html

Source file dashmap.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
type ('k, 'v) t = { tbl : ('k * 'v) list Atomic.t } [@@unboxed]

let create _size = { tbl = Atomic.make [] }
let entries t = Atomic.get t.tbl
let find t k = List.assoc_opt k (entries t)
let find_by t fn = List.find_opt fn (entries t)
let find_all_by t fn = List.find_all fn (entries t)
let has_key t k = find t k |> Option.is_some

let rec insert t k v =
  let tbl1 = entries t in
  let entry = (k, v) in
  if List.mem entry tbl1 then ()
  else
    let tbl2 = (k, v) :: tbl1 in
    if Atomic.compare_and_set t.tbl tbl1 tbl2 then () else insert t k v

let rec remove_by t fn =
  let tbl1 = entries t in
  let tbl2 = List.filter fn tbl1 in
  if Atomic.compare_and_set t.tbl tbl1 tbl2 then () else remove_by t fn

let rec replace t k v =
  let tbl1 = entries t in
  let tbl2 = (k, v) :: List.remove_assoc k tbl1 in
  if Atomic.compare_and_set t.tbl tbl1 tbl2 then () else replace t k v

let pp k_pp fmt t =
  Format.pp_print_list
    ~pp_sep:(fun fmt _ -> Format.fprintf fmt ", ")
    (fun fmt (k, _) -> k_pp fmt k)
    fmt (entries t)
OCaml

Innovation. Community. Security.