<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.ds-hashable.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'ds-hashable.hash.php',
    1 => 'Ds\\Hashable::hash',
    2 => 'Returns a scalar value to be used as a hash value',
  ),
  'up' => 
  array (
    0 => 'class.ds-hashable.php',
    1 => 'Ds\\Hashable',
  ),
  'prev' => 
  array (
    0 => 'ds-hashable.equals.php',
    1 => 'Ds\\Hashable::equals',
  ),
  'next' => 
  array (
    0 => 'class.ds-sequence.php',
    1 => 'Ds\\Sequence',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ds/ds/hashable/hash.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="ds-hashable.hash" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Ds\Hashable::hash</h1>
  <p class="verinfo">(PECL ds &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Hashable::hash</span> &mdash; <span class="dc-title">Returns a scalar value to be used as a hash value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-ds-hashable.hash-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><strong>Ds\Hashable::hash</strong></span>(): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
    Returns a scalar value to be used as the hash value of the objects.
  </p>
  <p class="para">
    While the hash value does not define equality, all objects that are equal according to <span class="function"><a href="ds-hashable.equals.php" class="function">Ds\Hashable::equals()</a></span>
    must have the same hash value. Hash values of equal objects don&#039;t have to be unique, for example
    you could just return <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> for all objects and nothing would break - the only
    implication would be that hash tables then turn into linked lists because all
    your objects will be hashed to the same bucket. It&#039;s therefore very important
    that you pick a good hash value, such as an ID or email address.
 </p>

  <p class="para">
    This method allows objects to be used as keys in structures such as
    <span class="classname"><a href="class.ds-map.php" class="classname">Ds\Map</a></span> and <span class="classname"><a href="class.ds-set.php" class="classname">Ds\Set</a></span>, or any
    other lookup structure that honors this interface.
  </p>

  <div class="caution"><strong class="caution">Achtung</strong>
    <p class="para">
        Do not pick a value that might change within the object, such as a public
        property. Hash table lookups would fail because the hash has changed.
    </p>
  </div>

  <div class="caution"><strong class="caution">Achtung</strong>
    <p class="para">
        All objects that are equal must have the same hash value.
    </p>
  </div>

 </div>


 <div class="refsect1 parameters" id="refsect1-ds-hashable.hash-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">Diese Funktion besitzt keine Parameter.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-ds-hashable.hash-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
    A scalar value to be used as this object&#039;s hash value.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-ds-hashable.hash-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 <span class="function"><strong>Ds\Hashable::hash()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">HashableObject </span><span style="color: #007700">implements </span><span style="color: #0000BB">\Ds\Hashable<br /></span><span style="color: #007700">{<br />    private </span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br />    private </span><span style="color: #0000BB">$email</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">, </span><span style="color: #0000BB">$email</span><span style="color: #007700">)<br />    {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name  </span><span style="color: #007700">= </span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email </span><span style="color: #007700">= </span><span style="color: #0000BB">$email</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #FF8000">/**<br />     * Should return the same value for all equal objects, but doesn't have to<br />     * be unique. This value will not be used to determine equality.<br />     */<br />    </span><span style="color: #007700">public function </span><span style="color: #0000BB">hash</span><span style="color: #007700">()<br />    {<br />        return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #FF8000">/**<br />     * This determines equality, usually during a hash table lookup to determine<br />     * if the bucket's key matches the lookup key. The hash has to be equal if<br />     * the objects are equal, otherwise this determination wouldn't be reached.<br />     */<br />    </span><span style="color: #007700">public function </span><span style="color: #0000BB">equals</span><span style="color: #007700">(</span><span style="color: #0000BB">$obj</span><span style="color: #007700">): </span><span style="color: #0000BB">bool<br />    </span><span style="color: #007700">{<br />        return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name  </span><span style="color: #007700">=== </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name<br />            </span><span style="color: #007700">&amp;&amp; </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email </span><span style="color: #007700">=== </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">email</span><span style="color: #007700">;<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>



</div><?php manual_footer($setup); ?>