diff --git a/src/proto_alpha/lib_protocol/bitset.ml b/src/proto_alpha/lib_protocol/bitset.ml index a49c4264ac05e2f7c6f24d5e95ebef680f7cd140..7f7792bf0803b3a400a1b6ea6c7242b42f944890 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 c7bf12064147e29f5bfa456ddae1cad1616c3910..96b101a56cfcf1cdcf6b20b465d61d0c8fad9188 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