Download the PHP package ft/sets without Composer
On this page you can find all versions of the php package ft/sets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sets
PHP lightweight hashtable (associative array) wrapper for Set data structures.
Sets are effectively containers that hold unique values.
Excogitation
What is 'unique'?
Unique is determined by this package via a hashed value for any given input. The hash value is generated internally for continuity. The hashed value is then used as a way to identify a hashtables element/value
Why create an internal hash code?
Why not use built-in spl_object_hash
or hash
There are many reasons why not to rely on these values, but fundamentally, they don't guarantee uniqueness.
Take for example:
The two objects are considered equal because they have the same amount of properties, the properties value's are identical and they both are derived stdClass objects.
However, the result of the 2 hashes:
Additionally spl_object_hash
only allows objects and hash|md5 etc
expect strings, not all objects include __toString()
logic.
In short, this is a very complex problem to solve because uniqueness is never not guaranteed, but the hash can and should limit potential collisions which the package strives for
Installation
composer require ft/sets
Set Classes
Set
A container that can hold zero to many elements of any data type
Class Diagram
StrictSet
A subclass of Set, which only permits the same data type to exist in a given instance
Note The first element added to a StrictSet dictates what type of elements can be added subsequently
When a StrictSet element is added that is not the same type an InvalidArgumentException
will be thrown. Subclasses of an element are not even permitted
SortedSet
A sorted set is one which the values are sorted in ascending order, or descending if elected.
Therefore sorted sets must contain the same elements (a la StrictSet
)
Additional functions are provided for numerical data types
Warning There is no locale integration for string comparisons, that's beyond the scope of this library