php8.5
Home/ Manual/ reference / ds/ The Set class

The Set class

A Set is a sequence of unique values. This implementation uses the same hash table as Ds\Map, where values are used as keys and the mapped value is ignored.

Intro

A Set is a sequence of unique values. This implementation uses the same hash table as Ds\Map, where values are used as keys and the mapped value is ignored.

Strengths

  • Values can be any type, including objects.
  • Supports array syntax (square brackets).
  • Insertion order is preserved.
  • Automatically frees allocated memory when its size drops low enough.
  • add(), remove() and contains() are all O(1).

Weaknesses

Class synopsis

class Ds\Set { }

Predefined Constants

Ds\Set::MIN_CAPACITY

Changelog

VersionDescription
PECL ds 1.3.0The class now implements ArrayAccess.
PECL ds 1.2.7Added the Ds\Set::map method.
PECL ds 1.2.0Ds\Set::MIN_CAPACITY changed from 16 to 8.

Set

Source: reference/ds/ds.set.xml · from the official PHP manual (php/doc-en)