Skip to content

Collections · API

Bitmap

A fixed number of on/off bits, numbered from 0. The width is the Bits passed to Bitmap.new. An index outside 0 to Bits - 1 is ignored: Set, Clear and Toggle do nothing, and Test returns false.

local Seen = Collections.Bitmap.new({ Bits = 64 })
Seen:Set(3)
print(Seen:Test(3), Seen:PopCount()) -- true 1
Member Description
.new() Creates a bitmap of Bits bits, all off.
:Set() Turns the bit at Index on.
:Clear() Turns the bit at Index off.
:Toggle() Flips the bit at Index.
:Test() Whether the bit at Index is on.
:ClearAll() Turns every bit off.
:SetAll() Turns every bit on.
:PopCount() How many bits are on.
:Raw() Returns the buffer that holds the bits.
function Bitmap.new(Config: { Bits: number }): Bitmap

Creates a bitmap of Bits bits, all off. Its width cannot change later.

function Bitmap:Set(Index: number)

Turns the bit at Index on.

function Bitmap:Clear(Index: number)

Turns the bit at Index off.

function Bitmap:Toggle(Index: number)

Flips the bit at Index.

function Bitmap:Test(Index: number): boolean

Whether the bit at Index is on.

function Bitmap:ClearAll()

Turns every bit off.

function Bitmap:SetAll()

Turns every bit on.

function Bitmap:PopCount(): number

How many bits are on.

function Bitmap:Raw(): buffer

Returns the buffer that holds the bits. Bit i is bit i % 32 of the u32 at byte (i // 32) * 4, and the bits past the width stay off.

© 2026 PRMS Developer