mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
document CCBitField with a raw test
This commit is contained in:
parent
aa28542959
commit
e54b5f32e6
2 changed files with 19 additions and 18 deletions
|
|
@ -73,6 +73,7 @@ module Make(X : EMPTY) : BITFIELD = struct
|
|||
width=2;
|
||||
get=(fun x -> (x land mask) lsr n);
|
||||
set=(fun v x ->
|
||||
assert (x >= 0 && x < 4);
|
||||
let x = x land (lnot mask) in
|
||||
x lor (v lsl n)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,29 +35,29 @@ module type BITFIELD = sig
|
|||
(** New field of type 2-bits int *)
|
||||
end
|
||||
|
||||
(** Create a new bitfield type
|
||||
|
||||
Example:
|
||||
(** Create a new bitfield type *)
|
||||
module Make(X : EMPTY) : BITFIELD
|
||||
|
||||
{[
|
||||
module B = CCBitField.Make(struct end);;
|
||||
(*$R
|
||||
let module B = CCBitField.Make(struct end) in
|
||||
|
||||
let x = B.bool ();;
|
||||
let y = B.int2 ();;
|
||||
let z = B.bool ();;
|
||||
let x = B.bool () in
|
||||
let y = B.int2 () in
|
||||
let z = B.bool () in
|
||||
|
||||
B.width y ;; (* = 2 *)
|
||||
assert_equal 2 (B.width y) ;
|
||||
|
||||
let f = B.empty
|
||||
|> B.set y 3
|
||||
|> B.set z true ;;
|
||||
(* = 14 *)
|
||||
|> B.set z true
|
||||
in
|
||||
|
||||
B.get x f ;; (* false *)
|
||||
B.get y f ;; (* 3 *)
|
||||
B.get z f ;; (* true *)
|
||||
assert_equal 14 (f :> int) ;
|
||||
|
||||
assert_equal false (B.get x f) ;
|
||||
assert_equal 3 (B.get y f) ;
|
||||
assert_equal (B.get z f);
|
||||
|
||||
()
|
||||
*)
|
||||
|
||||
]}
|
||||
|
||||
*)
|
||||
module Make(X : EMPTY) : BITFIELD
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue