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
12 bits = String.create (1 + size / 8);
15 let length v = v.length
20 (((Char.code (String.unsafe_get v.bits i)) lsr j) land 1) == 1
23 assert ( v1.length == v2.length );
24 let res = alloc v1.length in
25 (* Format.printf "size %d@." (String.length res.bits);*)
26 for i = 0 to String.length v1.bits - 1 do
27 res.bits.[i] <- Char.chr ((Char.code v1.bits.[i]) lor (Char.code v2.bits.[i]))
32 assert ( v1.length == v2.length );
33 let res = alloc v1.length in
34 for i = 0 to String.length v1.bits - 1 do
35 res.bits.[i] <- Char.chr ((Char.code v1.bits.[i]) land (Char.code v2.bits.[i]))
40 assert ( v1.length == v2.length );
41 let res = alloc v1.length in
42 for i = 0 to String.length v1.bits - 1 do
43 res.bits.[i] <- Char.chr ((Char.code v1.bits.[i]) land (lnot (Char.code v2.bits.[i])))
49 let unsafe_set v n (b:bool) =
50 let x : int = Obj.magic b in
54 let w = Char.code (String.unsafe_get v.bits i) in
55 let w = (w land lnot m) lor (~-x land m) in
56 String.unsafe_set v.bits i (Char.unsafe_chr (w land 0xff))
60 if n < 0 || n >= v.length then failwith "Bitvector.get"
65 if n < 0 || n >= v.length then failwith "Bitvector.set"