package hardcaml

  1. Overview
  2. Docs
RTL Hardware Design in OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.17.1.tar.gz
md5=7435ee8610c2205c5f912b4bf09163b0
sha512=38d7cf428bd3491024212e52776ac582183d7b5f6a494589a3697d9a213fa18347d6eeea23327859c340b0cb3b967c08cd21a8a7f8d15cf2de20e5598cb8456d

doc/src/hardcaml/combinational_ops_database.ml.html

Source file combinational_ops_database.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
open Base

type t = { by_name : (string, Combinational_op.t) Hashtbl.t } [@@deriving sexp_of]

let create () = { by_name = Hashtbl.create (module String) }
let find t ~(name : string) = Hashtbl.find t.by_name name

let insert t (op : Combinational_op.t) =
  let name = Combinational_op.name op in
  if Hashtbl.mem t.by_name name
  then
    raise_s
      [%message
        "A [Combinational_op] of the same name already exists in the database"
          (name : string)];
  Hashtbl.add_exn t.by_name ~key:name ~data:op
;;

let fold t ~init ~f = Hashtbl.fold t.by_name ~init ~f:(fun ~key:_ ~data a -> f a data)
let iter t ~f = Hashtbl.iter t.by_name ~f

let concat ts =
  let result = create () in
  List.iter ts ~f:(fun t -> iter t ~f:(fun op -> insert result op));
  result
;;