6 * @author Michael Wallner <mike@php.net>
10 use hikke\Event\Bucket
;
15 * @package hikke\Event
17 class Storage
implements \Iterator
, \Countable
22 private $sequence = 1;
27 private $buckets = array();
35 * @param object $object
36 * @param int|float $priority
37 * @return \hikke\Event\Bucket
39 public function insert($object, $priority = 0) {
40 $priority +
= $this->sequence++
/ 1000;
41 $bucket = new Bucket($object, $priority);
42 $this->buckets
[$bucket->getHash()] = $bucket;
47 * @param object $object
48 * @return bool whether the storage container the object
50 public function delete($object) {
51 $hash = spl_object_hash($object);
52 if (($found = isset($this->buckets
[$hash]))) {
53 unset($this->buckets
[$hash]);
61 public function count() {
62 return count($this->buckets
);
68 public function rewind() {
69 $this->iterator
= $this->buckets
;
70 uasort($this->iterator
, ["hikke\\Event\\Priority", "compare"]);
76 public function valid() {
77 return NULL !== key($this->iterator
);
83 public function next() {
84 next($this->iterator
);
90 public function key() {
91 return current($this->iterator
)->getPriority();
97 public function current() {
98 return current($this->iterator
)->getObject();