package obatcher

  1. Overview
  2. Docs
A Framework for building Batched Concurrent Data Structures

Install

Dune Dependency

Authors

Maintainers

Sources

obatcher-1.0.tbz
sha256=bad8af8223b14bd6d582e34eba90048d632f2ac611183e120d0faaeaefb7549e
sha512=cc8ede53c694abbb4aabb6f898e57057c6f2726411eb9f64b056652a0de7adf85432d55df5833d4555ccf03e681869ac0af218119c94f8577008ebd9e0601779

doc/src/obatcher.ds/batched_hashtbl.ml.html

Source file batched_hashtbl.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
(* Flat-combining hashtable, with no fancy internal parallelism *)

open Picos

module Batched = struct
  type t = (int, string) Stdlib.Hashtbl.t

  type 'a op =
    | Add : int * string -> unit op
    | Replace : int * string -> unit op
    | Remove : int -> unit op
    | Find : int -> string op

  type wrapped_op = Mk : 'a op * 'a Computation.t -> wrapped_op
  type cfg = { random : bool option; initial_size : int }

  let init ?(cfg = { random = None; initial_size = 0 }) () =
    Stdlib.Hashtbl.create ?random:cfg.random cfg.initial_size

  let run t (batch : wrapped_op array) =
    Array.iter
      (function
        | Mk (Add (k, v), comp) ->
            Computation.return comp (Stdlib.Hashtbl.add t k v)
        | Mk (Replace (k, v), comp) ->
            Computation.return comp (Stdlib.Hashtbl.replace t k v)
        | Mk (Remove k, comp) ->
            Computation.return comp (Stdlib.Hashtbl.remove t k)
        | Mk (Find k, comp) -> Computation.return comp (Stdlib.Hashtbl.find t k))
      batch
end

(* Set up implicit batching *)
include Obatcher.Make (Batched)
OCaml

Innovation. Community. Security.