Skip to content

Modern Set Set

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Set › Set › Set

Set

Holds each value at most once, in no particular order.

Syntax

Set( of T )

Notes

  • A Map with the value machinery removed, rather than a wrapper around one -- so it costs one slot per element instead of two.
  • Add returns FALSE when the element was already present, which is what makes if seen.Add( x ) then the natural spelling of "process each thing once".
  • The hash contract is Map's: the element type extends containers.Hashable (or is a built-in type), v = v must compare, and equal elements must hash equal.
  • Same implementation and same unspecified iteration order as Map.

Examples

#import "std/containers"
using containers

dim seen as Set( of integer )

print seen.Add( 42 )         '' true -- first time
print seen.Add( 42 )         '' false -- already there
print seen.Count             '' 1

'' Which is what makes this the way to process each thing once
dim as integer x = 7
if seen.Add( x ) then print "new"

Library: Set
Category: Set
Documented under: Members

Clone this wiki locally