Skip to content

Commit

Permalink
Merge pull request #218 from hannesm/entropy-sources
Browse files Browse the repository at this point in the history
use a set for entropy sources
  • Loading branch information
hannesm authored Mar 19, 2024
2 parents cfa9412 + 320d6cc commit 14006f2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rng/entropy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,26 @@ module Cpu_native = struct
| _ -> assert false
end

let _sources = ref []
module S = Set.Make(struct
type t = int * string
(* only the name is relevant for comparison - the idx not *)
let compare ((_a, an) : int * string) ((_b, bn) : int * string) =
String.compare an bn
end)

let _sources = ref S.empty

type source = Rng.source

let register_source name =
let n = List.length !_sources in
let n = S.cardinal !_sources in
let source = (n, name) in
_sources := source :: !_sources;
_sources := S.add source !_sources;
source

let id (idx, _) = idx

let sources () = !_sources
let sources () = S.elements !_sources

let pp_source ppf (idx, name) = Format.fprintf ppf "[%d] %s" idx name

Expand Down

0 comments on commit 14006f2

Please sign in to comment.