helly           Tue Nov 11 13:31:51 2003 EDT

  Added files:                 
    /spl/examples       seekableiterator.inc 

  Modified files:              
    /spl/examples       limititerator.inc 
  Log:
  Add shortcut interface SeekableIterator to LimitIterator
  
Index: spl/examples/limititerator.inc
diff -u spl/examples/limititerator.inc:1.1 spl/examples/limititerator.inc:1.2
--- spl/examples/limititerator.inc:1.1  Sun Nov  9 09:05:36 2003
+++ spl/examples/limititerator.inc      Tue Nov 11 13:31:50 2003
@@ -21,8 +21,12 @@
        {
                $this->it->rewind();
                $this->index = 0;
-               while($this->index < $this->offset && $this->it->hasMore()) {
-                       $this->next();
+               if (is_a($this->it, 'SeekableIterator')) {
+                       $this->index = $this->it->seek($this->offset);
+               } else {
+                       while($this->index < $this->offset && $this->it->hasMore()) {
+                               $this->next();
+                       }
                }
        }
        

Index: spl/examples/seekableiterator.inc
+++ spl/examples/seekableiterator.inc
<?php

class SeekableIterator implements Iterator
{
        function seek($index) {
                $this->rewind();
                $position = 0;
                while($position < $index && $this->it->hasMore()) {
                        $this->next();
                        $position++;
                }
                return $position;
        }
}

?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to