Skip to content

Collections · API

StampSet

A set of integers below a fixed size, which empties in one step. The size is the Capacity passed to StampSet.new. An integer outside 0 to Capacity - 1 is never in the set: Add and Test return false for it, and Remove ignores it.

Emptying costs the same however full the set is, so it suits marks that reset often, such as the cells one search has visited.

local Visited = Collections.StampSet.new({ Capacity = 1024 })
Visited:Add(42)
print(Visited:Test(42)) -- true
Visited:ClearAll()
print(Visited:Test(42)) -- false
Member Description
.new() Creates an empty set for the integers 0 to Capacity - 1.
:Add() Adds Index to the set, and returns whether it was newly added.
:Test() Whether Index is in the set.
:Remove() Removes Index from the set, if it is there.
:ClearAll() Empties the set in one step, however full it is.
:Count() How many integers the set holds.
StampSet The type StampSet.new returns.
function StampSet.new(Config: { Capacity: number }): StampSet

Creates an empty set for the integers 0 to Capacity - 1. It allocates 4 bytes per integer up front.

Parameter Type Description
Config { Capacity: number } Capacity sets the range, and cannot change later
function StampSet:Add(Index: number): boolean

Adds Index to the set, and returns whether it was newly added.

function StampSet:Test(Index: number): boolean

Whether Index is in the set.

function StampSet:Remove(Index: number)

Removes Index from the set, if it is there.

function StampSet:ClearAll()

Empties the set in one step, however full it is. About once every four billion calls it also zero-fills its buffer, which takes time in proportion to Capacity.

function StampSet:Count(): number

How many integers the set holds.

export type StampSet = {
	Add: (self: StampSet, Index: number) -> boolean,
	Test: (self: StampSet, Index: number) -> boolean,
	Remove: (self: StampSet, Index: number) -> (),
	ClearAll: (self: StampSet) -> (),
	Count: (self: StampSet) -> number,
}

The type StampSet.new returns.

© 2026 PRMS Developer