PHPackages                             ft/sets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ft/sets

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

ft/sets
=======

A lightweight flexible PHP hashstable wrapper package for Sets

1.0.1(3y ago)0141MITPHPPHP &gt;=8.1

Since Jan 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/soulshined/ft-sets)[ Packagist](https://packagist.org/packages/ft/sets)[ RSS](/packages/ft-sets/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

PHP lightweight hashtable (associative array) wrapper for Set data structures.

Sets are effectively containers that hold unique values.

Excogitation
------------

[](#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:

```
$aStd = new stdClass;
$aStd->foo = "foobar";

$bStd = new stdClass;
$bStd->foo = "foobar";
```

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:

```
var_dump(spl_object_hash($aStd)); //00000000000000010000000000000000
var_dump(spl_object_hash($bStd)); //00000000000000020000000000000000

```

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
------------

[](#installation)

`composer require ft/sets`

Set Classes
-----------

[](#set-classes)

### `Set`

[](#set)

A container that can hold zero to many elements of any data type

 Class Diagram ```
classDiagram
    class Countable {

        public count(): int
    }
    class Traversable {

    }
    class Iterator {

        public rewind(): void
        public current(): mixed
        public key(): mixed
        public next(): void
        public valid(): bool
    }
    Countable
