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; }
static function __static() { self::$instance = new self(); // Workaround for bugs in older PHP versions, see MD5HexHashImplementation's // class apidoc for an explanation. Earlier versions returned LONG_MAX for // hex numbers larger than LONG_MAX. Use 2^64 + 1 as hex literal and see if // it's "truncated", using the slower hexdec(md5()) implementation then. if (LONG_MAX === @0.0) { $impl = XPClass::forName('util.collections.MD5HexHashImplementation')->newInstance(); } else { $impl = new MD5HashImplementation(); } self::$instance->setImplementation($impl); }
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; }
/** * 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)); }
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; }
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; }