Esempio n. 1
0
 public function pop()
 {
     if (empty($this->_elements)) {
         throw new NoSuchElementException('Stack is empty');
     }
     $element = array_shift($this->_elements);
     $h = $element instanceof Generic ? $element->hashCode() : serialize($element);
     $this->_hash += HashProvider::hashOf($h);
     return $element;
 }
Esempio n. 2
0
 public function remove($key)
 {
     $h = $key instanceof Generic ? $key->hashCode() : serialize($key);
     if (!isset($this->_buckets[$h])) {
         $prev = NULL;
     } else {
         $prev = $this->_buckets[$h][1];
         $this->_hash -= HashProvider::hashOf($h . ($prev instanceof Generic ? $prev->hashCode() : $prev));
         unset($this->_buckets[$h]);
     }
     return $prev;
 }
Esempio n. 3
0
 /**
  * Returns a hashcode for this pair
  *
  * @return string
  */
 public function hashCode()
 {
     return HashProvider::hashOf($this->key instanceof Generic ? $this->key->hashCode() : serialize($this->key)) + HashProvider::hashOf($this->value instanceof Generic ? $this->value->hashCode() : serialize($this->value));
 }
Esempio n. 4
0
 public function remove($element)
 {
     if (-1 == ($pos = $this->search($element))) {
         return FALSE;
     }
     $element = $this->_elements[$pos];
     $h = $element instanceof Generic ? $element->hashCode() : serialize($element);
     $this->_hash -= HashProvider::hashOf($h);
     unset($this->_elements[$pos]);
     $this->_elements = array_values($this->_elements);
     // Re-index
     return TRUE;
 }
Esempio n. 5
0
 public function addAll($elements)
 {
     $changed = FALSE;
     foreach ($elements as $element) {
         $h = $element instanceof Generic ? $element->hashCode() : serialize($element);
         if (isset($this->_elements[$h])) {
             continue;
         }
         $this->_hash += HashProvider::hashOf($h);
         $this->_elements[$h] = $element;
         $changed = TRUE;
     }
     return $changed;
 }