<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>The Set class</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-pair.toarray.html">Ds\Pair::toArray</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-set.add.html">Ds\Set::add</a></div> <div class="up"><a href="book.ds.html">Data Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="class.ds-set" class="reference"> <h1 class="title">The Set class</h1> <div class="partintro"><p class="verinfo">(No version information available, might only be in Git)</p> <div class="section" id="ds-set.intro"> <h2 class="title">Introduction</h2> <p class="para"> A Set is a sequence of unique values. This implementation uses the same hash table as <strong class="classname">Ds\Map</strong>, where values are used as keys and the mapped value is ignored. </p> </div> <div class="section" id="ds-set.strengths"> <h2 class="title">Strengths</h2> <p class="para"> <ul class="simplelist"> <li class="member">Values can be any type, including objects.</li> <li class="member">Supports array syntax (square brackets).</li> <li class="member">Insertion order is preserved.</li> <li class="member">Automatically frees allocated memory when its size drops low enough.</li> <li class="member"> <span class="function"><strong>add()</strong></span>, <span class="function"><strong>remove()</strong></span> and <span class="function"><strong>contains()</strong></span> are all O(1). </li> </ul> </p> </div> <div class="section" id="ds-set.weaknesses"> <h2 class="title">Weaknesses</h2> <p class="para"> <ul class="simplelist"> <li class="member">Doesn’t support <span class="function"><strong>push()</strong></span>, <span class="function"><strong>pop()</strong></span>, <span class="function"><strong>insert()</strong></span>, <span class="function"><strong>shift()</strong></span>, or <span class="function"><strong>unshift()</strong></span>. </li> <li class="member"> <span class="function"><strong>get()</strong></span> is O(n) if there are deleted values in the buffer before the accessed index, O(1) otherwise. </li> </ul> </p> </div> <div class="section" id="ds-set.synopsis"> <h2 class="title">Class synopsis</h2> <div class="classsynopsis"> <div class="ooclass"></div> <div class="classsynopsisinfo"> <span class="ooclass"> <strong class="classname">Ds\Set</strong> </span> <span class="oointerface">implements <span class="interfacename"><strong class="interfacename">Ds\Collection</strong></span> </span> {</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div> <div class="fieldsynopsis"> <span class="modifier">const</span> <span class="type">int</span> <var class="fieldsynopsis_varname"><a href="class.ds-set.html#ds-set.constants.min-capacity"><var class="varname">MIN_CAPACITY</var></a></var> <span class="initializer"> = 16</span> ;</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.add.html" class="methodname">add</a></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...values</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.allocate.html" class="methodname">allocate</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$capacity</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><a href="ds-set.capacity.html" class="methodname">capacity</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.clear.html" class="methodname">clear</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><a href="ds-set.contains.html" class="methodname">contains</a></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...values</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.copy.html" class="methodname">copy</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.diff.html" class="methodname">diff</a></span> ( <span class="methodparam"><span class="type"><span class="type Ds\Set">Ds\Set</span></span> <code class="parameter">$set</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.filter.html" class="methodname">filter</a></span> ([ <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.first.html" class="methodname">first</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">mixed</span> <span class="methodname"><a href="ds-set.get.html" class="methodname">get</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.intersect.html" class="methodname">intersect</a></span> ( <span class="methodparam"><span class="type"><span class="type Ds\Set">Ds\Set</span></span> <code class="parameter">$set</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><a href="ds-set.isempty.html" class="methodname">isEmpty</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><a href="ds-set.join.html" class="methodname">join</a></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$glue</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.last.html" class="methodname">last</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.merge.html" class="methodname">merge</a></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$values</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">mixed</span> <span class="methodname"><a href="ds-set.reduce.html" class="methodname">reduce</a></span> ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$initial</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.remove.html" class="methodname">remove</a></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...values</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.reverse.html" class="methodname">reverse</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.reversed.html" class="methodname">reversed</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.slice.html" class="methodname">slice</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="ds-set.sort.html" class="methodname">sort</a></span> ([ <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.sorted.html" class="methodname">sorted</a></span> ([ <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">number</span> <span class="methodname"><a href="ds-set.sum.html" class="methodname">sum</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><a href="ds-set.toarray.html" class="methodname">toArray</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.union.html" class="methodname">union</a></span> ( <span class="methodparam"><span class="type"><span class="type Ds\Set">Ds\Set</span></span> <code class="parameter">$set</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">Ds\Set</span> <span class="methodname"><a href="ds-set.xor.html" class="methodname">xor</a></span> ( <span class="methodparam"><span class="type"><span class="type Ds\Set">Ds\Set</span></span> <code class="parameter">$set</code></span> )</div> }</div> </div> <div class="section" id="ds-set.constants"> <h2 class="title">Predefined Constants</h2> <dl> <dt id="ds-set.constants.min-capacity"><strong><code>Ds\Set::MIN_CAPACITY</code></strong></dt> <dd> <p class="para"/> </dd> </dl> </div> </div> <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="ds-set.add.html">Ds\Set::add</a> — Adds values to the set</li><li><a href="ds-set.allocate.html">Ds\Set::allocate</a> — Allocates enough memory for a required capacity</li><li><a href="ds-set.capacity.html">Ds\Set::capacity</a> — Returns the current capacity</li><li><a href="ds-set.clear.html">Ds\Set::clear</a> — Removes all values</li><li><a href="ds-set.construct.html">Ds\Set::__construct</a> — Creates a new instance</li><li><a href="ds-set.contains.html">Ds\Set::contains</a> — Determines if the set contains all values</li><li><a href="ds-set.copy.html">Ds\Set::copy</a> — Returns a shallow copy of the set</li><li><a href="ds-set.count.html">Ds\Set::count</a> — Returns the number of values in the set</li><li><a href="ds-set.diff.html">Ds\Set::diff</a> — Creates a new set using values that aren't in another set</li><li><a href="ds-set.filter.html">Ds\Set::filter</a> — Creates a new set using a callable to determine which values to include</li><li><a href="ds-set.first.html">Ds\Set::first</a> — Returns the first value in the set</li><li><a href="ds-set.get.html">Ds\Set::get</a> — Returns the value at a given index</li><li><a href="ds-set.intersect.html">Ds\Set::intersect</a> — Creates a new set by intersecting values with another set</li><li><a href="ds-set.isempty.html">Ds\Set::isEmpty</a> — Returns whether the set is empty</li><li><a href="ds-set.join.html">Ds\Set::join</a> — Joins all values together as a string</li><li><a href="ds-set.jsonserialize.html">Ds\Set::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="ds-set.last.html">Ds\Set::last</a> — Returns the last value in the set</li><li><a href="ds-set.merge.html">Ds\Set::merge</a> — Returns the result of adding all given values to the set</li><li><a href="ds-set.reduce.html">Ds\Set::reduce</a> — Reduces the set to a single value using a callback function</li><li><a href="ds-set.remove.html">Ds\Set::remove</a> — Removes all given values from the set</li><li><a href="ds-set.reverse.html">Ds\Set::reverse</a> — Reverses the set in-place</li><li><a href="ds-set.reversed.html">Ds\Set::reversed</a> — Returns a reversed copy</li><li><a href="ds-set.slice.html">Ds\Set::slice</a> — Returns a sub-set of a given range</li><li><a href="ds-set.sort.html">Ds\Set::sort</a> — Sorts the set in-place</li><li><a href="ds-set.sorted.html">Ds\Set::sorted</a> — Returns a sorted copy</li><li><a href="ds-set.sum.html">Ds\Set::sum</a> — Returns the sum of all values in the set</li><li><a href="ds-set.toarray.html">Ds\Set::toArray</a> — Converts the set to an array</li><li><a href="ds-set.union.html">Ds\Set::union</a> — Creates a new set using values from the current instance and another set</li><li><a href="ds-set.xor.html">Ds\Set::xor</a> — Creates a new set using values in either the current instance or in another set, but not in both</li></ul> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ds-pair.toarray.html">Ds\Pair::toArray</a></div> <div class="next" style="text-align: right; float: right;"><a href="ds-set.add.html">Ds\Set::add</a></div> <div class="up"><a href="book.ds.html">Data Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>