Expand description
Two-dimensional runs: rectangular blocks in a bitmap of rows.
One word per row, bit c of row r is cell (r, c). Finding a
w × h block of set cells is separable: the halving chain of
Bits::run_starts applied down the rows (rows r..r + h all
set, ⌈log₂ h⌉ passes) and then along each row (⌈log₂ w⌉
steps). In morphology terms this is binary erosion by a w × h
rectangle; in allocator terms it is first-fit of a rectangle over
a tile bitmap, texture atlases, sparse-texture page tables,
inventory grids, occupancy grids.
Composition carries over from one dimension:
block_starts(block_starts(g, w₁, h₁), w₂, h₂) = block_starts(g, w₁ + w₂ − 1, h₁ + h₂ − 1).
Grids narrower than BITS columns must keep unused columns clear.
Functions§
- block_
starts - Writes into
out[r]the columnscat which aw × hblock of set cells starts at(r, c).out.len() == rows.len(); rows that cannot fithmore rows come out zero.win1..=BITS,h >= 1. - clear_
block - Clears every cell of the
w × hblock at(row, col), asfill_blocksets them. - fill_
block - Sets every cell of the
w × hblock at(row, col). The block must lie inside the grid (debug-asserted). - find_
block - First-fit (row-major) position
(row, col)of aw × hblock of set cells, usingscratch(same length asrows) as workspace.