The Set class
Guide
Edit on GitHub ✎
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()andcontains()are all O(1).
Weaknesses
- Doesn’t support
push(),pop(),insert(),shift(), orunshift(). get()is O(n) if there are deleted values in the buffer before the accessed index, O(1) otherwise.
Class synopsis
class Ds\Set { }
Predefined Constants
Ds\Set::MIN_CAPACITY
Changelog
| Version | Description |
|---|---|
| PECL ds 1.3.0 | The class now implements ArrayAccess. |
| PECL ds 1.2.7 | Added the Ds\Set::map method. |
| PECL ds 1.2.0 | Ds\Set::MIN_CAPACITY changed from 16 to 8. |
Set