\Phabstractic\Data\Types\ResourceSetInterface

Set Interface - Defines A Set Data Structure

A set is a collection of values that are unique. In mathematical terms it is an implementation of a finite set. Usually you test if something exists or doesn't exist inside the set. You can also set up operations on sets themselves, much like an array map. You can also easily perform unions, intersections, and many operations traditional to set theory and the set data type.

Summary

Methods
Constants
getArray()
getArrayReference()
getPlainArray()
retrieveReference()
add()
addReference()
remove()
removeByIdentifier()
in()
isEmpty()
size()
iterate()
enumerate()
pop()
clear()
hash()
equal()
fold()
filter()
map()
walk()
build()
union()
intersection()
difference()
subset()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

getArray()

getArray() : array

Get the Set as Array

Return the set contents as an array

Returns

array —

The set represented as an array

getArrayReference()

getArrayReference() : array

Get the Set's Array

Return the set's array by reference

Returns

array —

The set's internal array

getPlainArray()

getPlainArray() : array

Get the Set as a PLAIN Array

Return the set contents as an array without string keys

NOTE: All elements are references to internal array elements

Returns

array —

The set represented as a plain array

retrieveReference()

retrieveReference(mixed  $identifier) : \Phabstractic\Data\Types\Resource\mixed;

If the value is in the set, this retrieves a reference to it

This only works if the set is considered unique

Parameters

mixed $identifier

The identifier returned by the add function

Returns

\Phabstractic\Data\Types\Resource\mixed;

add()

add(mixed  $value) : string

Add a value to the set, respects 'unique' option

Parameters

mixed $value

The value to add to the set.

Returns

string —

The internal datum identifier

addReference()

addReference(mixed  $value) : string

Add a value to the set as a reference, respects 'strict' option

Parameters

mixed $value

The value to add to the set.

Returns

string —

The internal datum identifier

remove()

remove(mixed  $value) 

Remove a value from the set

Respects 'strict' option: the set must contain the value to be removed.

Parameters

mixed $value

The value to be removed from the set.

removeByIdentifier()

removeByIdentifier(  $identity) 

Remove a value from the set

This uses a previously given identifier to remove an element from the set. If the identifier doesn't exist it returns false.

Parameters

$identity

in()

in(mixed  $value) 

Basic in_array wrapper for the set

Parameters

mixed $value

The value to check against the data

isEmpty()

isEmpty() : boolean

Is the internal data array empty?

Returns

boolean

size()

size() : integer

Basic count wrapper for the set

Returns

integer —

Size of data array

iterate()

iterate() : \ArrayIterator

This allows us to use the Set data in a basic iterator Being, \ArrayIterator

Returns

\ArrayIterator —

The iterator to use in a loop

enumerate()

enumerate() : array

Synonym for getArray()

Returns

array —

The data array of the set

pop()

pop() : mixed

Pop the first/next value defined the set

This deletes the value from the set

Returns

mixed —

The value 'popped' from the Set

clear()

clear() 

Eliminate Set data completely

hash()

hash() : string

Return a hash (unique) of the entire set

Derived from the Set data: "returns a hash value for the static set S such that if equal(S1, S2) then hash(S1) = hash(S2)"

Returns

string —

The hash of the set data

fold()

fold(callable  $F, \Phabstractic\Data\Types\Resource\Set  $S) : mixed

Apply a function to each element of the set, reducing to a single function

"returns the value A|S| after applying Ai+1 := F(Ai, e) for each element e of S."

Parameters

callable $F

The applicable function.

\Phabstractic\Data\Types\Resource\Set $S

The Set to fold

Returns

mixed —

The value resulting from the 'fold' (array_reduce)

filter()

filter(callable  $F, \Phabstractic\Data\Types\Resource\Set  $S) : array

Returns only elements that satisfy a 'predicate'

The predicate here is a function that returns true or false on any given item "returns the subset containing all elements of S that satisfy a given predicate P."

Parameters

callable $F

The applicable predicate function.

\Phabstractic\Data\Types\Resource\Set $S

The Set to filter

Returns

array —

The filtered aray

map()

map(callable  $F, \Phabstractic\Data\Types\Resource\Set  $S) : array

Apply a function to each element of the set

"returns the set of distinct values resulting from applying function F to each element of S."

Parameters

callable $F

The applicable function.

\Phabstractic\Data\Types\Resource\Set $S

The Set to map

Returns

array —

The resulting distinct set

walk()

walk(\Phabstractic\Data\Types\Resource\SetInterface  $S, callable  $F, mixed  $D) : boolean

Applies the given function, plus any additional arguments ($args) past the given function argument to each element of theset.

Note: Unlike Map, this operates on a reference of the set

Parameters

\Phabstractic\Data\Types\Resource\SetInterface $S
callable $F

the applicablt function

mixed $D

the user data

Returns

boolean —

True on Success, False otherwise

build()

build(array  $values = array()) : \Phabstractic\Data\Types\Resource\Set

Create a set from an array

Just hands back a Set created from a given array "creates a set structure with values x1,x2,…,xn."

Parameters

array $values

The values of the set (which are 'uniqued' in the construction)

Returns

\Phabstractic\Data\Types\Resource\Set

union()

union() : array

Set Union

"returns the union of sets S and T."

This function can take multiple arrays, sets, or values mixed together

Returns

array —

Unioned array

intersection()

intersection() : array

Set Intersection

"returns the intersection of sets S and T."

This function can take multiple arrays, Sets, or values mixed together

Returns

array —

Intersected array

difference()

difference() : array

Set Difference

"returns the difference of sets S and T."

This function can take multiple arrays, Sets, or values mixed together

Returns

array —

Difference array

subset()

subset(\Phabstractic\Data\Types\Resource\Set  $S, \Phabstractic\Data\Types\Resource\Set  $T) : boolean

Set Filter

"a predicate that tests whether the set S is a subset of set T."

This function tests whether all elements of S are in T

Parameters

\Phabstractic\Data\Types\Resource\Set $S

The first set

\Phabstractic\Data\Types\Resource\Set $T

The comparison/parent set

Returns

boolean