Skip to content

Remove the Build traits from bit_vectors and int_vectors - #129

Merged
kampersanda merged 1 commit into
mainfrom
claude/bit-int-vector-build-trait-817473
Oct 10, 2026
Merged

kampersanda merged 1 commit into
mainfrom
claude/bit-int-vector-build-trait-817473

Conversation

@kampersanda

Copy link
Copy Markdown
Owner

Summary

  • Remove bit_vectors::Build and int_vectors::Build, along with their impls and prelude re-exports.
  • Change WaveletMatrix::new to take a closure that builds each layer from a BitVector.
  • Update module docs, tests, and the bench crate accordingly.

Why

The Build traits were an over-abstraction:

  • bit_vectors::Build::build_from_bits(bits, with_rank, with_select1, with_select0) took three positional bools whose meaning differed per type. BitVector ignored all of them, Rank9Sel ignored with_rank, DArray ignored with_select1, and SArray returned an error for with_select0. Unsupported features were only detected at runtime.
  • Every impl just forwarded to the type's own constructors (from_bits, enable_rank, select1_hints, ...).
  • int_vectors::Build had no generic users at all, wrapped infallible constructors in Result, and hid DacsOpt's max_levels parameter.
  • The only generic user was WaveletMatrix::new.

New WaveletMatrix API

pub fn new<F>(seq: CompactVector, build_layer: F) -> Result<Self>
where
    F: FnMut(BitVector) -> B,
let wm = WaveletMatrix::new(seq, Rank9Sel::new)?;
let wm = WaveletMatrix::new(seq, |bv| Rank9Sel::new(bv).select1_hints().select0_hints())?;

The bench crate keeps the previous configurations (Rank9Sel with both select hints; DArray with enable_rank().enable_select0()).

Notes for reviewers

  • Breaking change: public traits are removed and WaveletMatrix::new gains an argument. This should go into 0.10.0.
  • SArray still cannot be used as a WaveletMatrix layer because it lacks select0. Previously this failed at construction with an error; now it panics when select is called. The new docs state that layers must support both select1 and select0.
  • SArray's test_rs_build_with_s0 was removed since the code path it tested no longer exists.

Test plan

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::nursery
  • cargo clippy --all-targets --no-default-features -- -D warnings -W clippy::nursery
  • cargo test / cargo test --release --no-default-features
  • cargo doc --no-deps

🤖 Generated with Claude Code

The `Build` traits duplicated each type's own constructors and hid
type-specific behavior behind boolean flags whose meanings differed per
implementation (some ignored, some rejected at runtime). The only generic
user was `WaveletMatrix::new`.

`WaveletMatrix::new` now takes a closure that builds each layer from a
`BitVector`, e.g. `WaveletMatrix::new(seq, Rank9Sel::new)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kampersanda
kampersanda merged commit 6024276 into main Oct 10, 2026
7 checks passed
@kampersanda
kampersanda deleted the claude/bit-int-vector-build-trait-817473 branch October 10, 2026 00:10
@kampersanda kampersanda mentioned this pull request Oct 10, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant