Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ sieve.opt

bench.exe
perf.data
bench_pbv.exe
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

- new module [Pbv] for persistent bit vectors

# 2.1 (22/08/2025)
- fixed bug in `random`
- fixed negative `max_length` on JavaScript platform
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ opam install bitv

## Usage

The library provides a single module, `Bitv`. The documentation is
available [here](https://backtracking.github.io/bitv).
The library provides two modules:
- `Bitv`, for imperative bit vectors;
- `Pbv`, for persistence bit vectors.

The documentation is available
[here](https://backtracking.github.io/bitv).

## Bug reports

Expand Down
27 changes: 27 additions & 0 deletions bench_pbv.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

(* sandbox to test performance *)

open Format

let time f x =
let open Unix in
let u = (times()).tms_utime in
let y = f x in
let ut = (times()).tms_utime -. u in
printf "%2.2f@." ut;
y

open Bitv__Pbv

let () = Random.init 42
let n = int_of_string Sys.argv.(1)

module M = Small(struct let size = Sys.int_size end)
open M
let v = init 63 (fun i -> i < n)
let () = printf "v = %a@." print v
let f v =
let s = ref 0 in
iter_subsets (fun v -> s := !s + pop v) v;
printf "sum = %d@." !s
let () = time f v
8 changes: 6 additions & 2 deletions bitv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
the same operations as module [Array]. It also provides bitwise operations
and conversions to/from integer types.

In the following, [false] stands for bit 0 and [true] for bit 1. *)
In the following, [false] stands for bit 0 and [true] for bit 1.

This is an imperative data structure. For persistence bit vectors,
see module [Pbv].
*)

type t
(** the type of bit vectors *)
Expand All @@ -27,7 +31,7 @@ type t

val create : int -> bool -> t
(** [(Bitv.create n b)] creates a new bit vector of length [n],
initialized with [b]. *)
initialized with [b]. *)

val init : int -> (int -> bool) -> t
(** [(Bitv.init n f)] returns a fresh vector of length [n],
Expand Down
15 changes: 14 additions & 1 deletion dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(public_name bitv)
(flags
(:standard -w -32))
(modules bitv))
(modules bitv pbv))

(library
(public_name bitv.string)
Expand All @@ -15,6 +15,13 @@
(modules test)
(libraries bitv))

(test
(name test_pbv)
(modules test_pbv)
(flags
(:standard -w -32))
(libraries bitv))

(test
(name sieve)
(modules sieve)
Expand All @@ -25,3 +32,9 @@
(modules bench)
(promote (until-clean))
(libraries unix bitv))

(executable
(name bench_pbv)
(modules bench_pbv)
(promote (until-clean))
(libraries unix bitv))
Loading