From 244edfbd3d3897dac98b919db4d3a3081b876946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Sep 2022 14:49:46 +0200 Subject: [PATCH] Protocol/Bitset: Add more functions --- src/proto_alpha/lib_protocol/bitset.ml | 4 ++++ src/proto_alpha/lib_protocol/bitset.mli | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/proto_alpha/lib_protocol/bitset.ml b/src/proto_alpha/lib_protocol/bitset.ml index a49c4264ac05..7f7792bf0803 100644 --- a/src/proto_alpha/lib_protocol/bitset.ml +++ b/src/proto_alpha/lib_protocol/bitset.ml @@ -39,6 +39,10 @@ let add field pos = error_when Compare.Int.(pos < 0) (Invalid_position pos) >>? fun () -> ok @@ Z.logor field Z.(shift_left one pos) +let from_list positions = List.fold_left_e add empty positions + +let inter = Z.logand + let () = let open Data_encoding in register_error_kind diff --git a/src/proto_alpha/lib_protocol/bitset.mli b/src/proto_alpha/lib_protocol/bitset.mli index c7bf12064147..96b101a56cfc 100644 --- a/src/proto_alpha/lib_protocol/bitset.mli +++ b/src/proto_alpha/lib_protocol/bitset.mli @@ -44,6 +44,13 @@ val mem : t -> int -> bool tzresult This functions returns [Invalid_input i] if [i] is negative. *) val add : t -> int -> t tzresult +(** [from_list positions] folds [add] over the [positions] starting from [empty]. *) +val from_list : int list -> t tzresult + +(** [inter field_l field_r] returns [field] which is result of the + logical "and" bit-wise from [field_l] and [field_r]. *) +val inter : t -> t -> t + (** [occupied_size_in_bits bitset] returns the current number of bits occupied by the [bitset]. *) val occupied_size_in_bits : t -> int -- GitLab