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)) -- trueVisited:ClearAll()print(Visited:Test(42)) -- falseSummary
Section titled “Summary”| 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. |
Functions
Section titled “Functions”function StampSet.new(Config: { Capacity: number }): StampSetCreates 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 |
Methods
Section titled “Methods”function StampSet:Add(Index: number): booleanAdds Index to the set, and returns whether it was newly added.
function StampSet:Test(Index: number): booleanWhether Index is in the set.
Remove
Section titled “Remove”function StampSet:Remove(Index: number)Removes Index from the set, if it is there.
ClearAll
Section titled “ClearAll”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(): numberHow many integers the set holds.
StampSet
Section titled “StampSet”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