ac-library-hs-1.1.0.0: Data structures and algorithms
Safe HaskellSafe-Inferred
LanguageGHC2021

AtCoder.Extra.WaveletMatrix.BitVector

Description

A compact bit vector, a collection of bits that can process rank in \(O(1)\) and select in \(O(\log n)\).

Since: 1.1.0.0

Synopsis

Bit vector

data BitVector Source #

A compact bit vector.

Since: 1.1.0.0

Constructors

BitVector 

Fields

Instances

Instances details
Show BitVector Source # 
Instance details

Defined in AtCoder.Extra.WaveletMatrix.BitVector

Eq BitVector Source # 
Instance details

Defined in AtCoder.Extra.WaveletMatrix.BitVector

Constructor

build :: Vector Bit -> BitVector Source #

\(O(n)\) Creates a BitVector.

Since: 1.1.0.0

(Internal) Word-based cumultaive sum

wordSize :: Int Source #

The block size \(64\) for the internal cumultaive sum in the bit vector.

Since: 1.1.0.0

csumInPlace Source #

Arguments

:: PrimMonad m 
=> MVector (PrimState m) Int

Cumulative sum of length \(\lceil |\mathrm{bits}| / 64 \rceil\).

-> Vector Bit

Bits

-> m Int

Sum of the bits

\(O(n)\) Calculates the cumulative sum in-place for the bit vector and returns the sum.

Since: 1.1.0.0

Rank

rank0 :: BitVector -> Int -> Int Source #

\(O(1)\) Counts the number of \(0\) bits in the interval \([0, i)\).

Since: 1.1.0.0

rank1 :: BitVector -> Int -> Int Source #

\(O(1)\) Counts the number of \(1\) bits in an interval \([0, i)\).

Since: 1.1.0.0

Select

select0 :: BitVector -> Int -> Maybe Int Source #

\(O(\log n)\) Returns the index of \(k\)-th \(0\) (0-based), or Nothing if no such bit exists.

Since: 1.1.0.0

select1 :: BitVector -> Int -> Maybe Int Source #

\(O(\log n)\) Returns the index of \(k\)-th \(1\) (0-based), or Nothing if no such bit exists.

Since: 1.1.0.0

selectKthIn0 Source #

Arguments

:: BitVector

A bit vector

-> Int

\(l\)

-> Int

\(r\)

-> Int

\(k\)

-> Maybe Int

The index of \(k\)-th \(0\) in \([l, r)\)

\(O(\log n)\) Returns the index of \(k\)-th \(0\) (0-based) in \([l, r)\), or Nothing if no such bit exists.

Since: 1.1.0.0

selectKthIn1 Source #

Arguments

:: BitVector

A bit vector

-> Int

\(l\)

-> Int

\(r\)

-> Int

\(k\)

-> Maybe Int

The index of \(k\)-th \(1\) in \([l, r)\)

\(O(\log n)\) Returns the index of \(k\)-th \(1\) (0-based) in \([l, r)\), or Nothing if no such bit exists.

Since: 1.1.0.0