1 type t = { length : int;
4 let create ?(init=false) size =
5 let i = if init then '\xff' else '\x00' in
7 bits = String.make (1 + size / 8) i
10 let length v = v.length
15 (((Char.code (String.unsafe_get v.bits i)) lsr j) land 1) == 1
18 assert ( v1.length == v2.length );
19 let res = create v1.length in
20 (* Format.printf "size %d@." (String.length res.bits);*)
21 for i = 0 to String.length v1.bits - 1 do
22 res.bits.[i] <- Char.chr ((Char.code v1.bits.[i]) lor (Char.code v2.bits.[i]))
27 assert ( v1.length == v2.length );
28 let res = create v1.length in
29 for i = 0 to String.length v1.bits - 1 do
30 res.bits.[i] <- Char.chr ((Char.code v1.bits.[i]) land (Char.code v2.bits.[i]))
35 assert ( v1.length == v2.length );
36 let res = create v1.length in
37 for i = 0 to String.length v1.bits - 1 do
38 res.bits.[i] <- Char.chr (if (Char.code v1.bits.[i]) != ( (Char.code v2.bits.[i])) then 1
45 let unsafe_set v n (b:bool) =
46 let x : int = Obj.magic b in
50 let w = Char.code (String.unsafe_get v.bits i) in
51 let w = (w land lnot m) lor (~-x land m) in
52 String.unsafe_set v.bits i (Char.unsafe_chr (w land 0xff))
56 if n < 0 || n >= v.length then failwith "Bitvector.get"
61 if n < 0 || n >= v.length then failwith "Bitvector.set"