]> granicus.if.org Git - php/commitdiff
- Fix comparison of RecursiveDualIterators
authorMarcus Boerger <helly@php.net>
Sun, 10 Dec 2006 23:44:35 +0000 (23:44 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 10 Dec 2006 23:44:35 +0000 (23:44 +0000)
ext/spl/examples/dualiterator.inc
ext/spl/examples/recursivecomparedualiterator.inc [new file with mode: 0755]
ext/spl/examples/recursivedualiterator.inc
ext/spl/examples/tests/dualiterator_001.phpt

index 3db4487c4ae4e6785d1d38eb71622b6643099384..9d14328d74ca50296c1fcaf51865c02929855936 100755 (executable)
@@ -12,7 +12,7 @@
 /** @ingroup Examples
  * @brief   Synchronous iteration over two iterators
  * @author  Marcus Boerger
- * @version 1.2
+ * @version 1.3
  */
 class DualIterator implements Iterator
 {
@@ -174,7 +174,7 @@ class DualIterator implements Iterator
                        {
                                $it = new RecursiveDualIterator($lhs, $rhs, 
                                                                self::CURRENT_0 | self::KEY_0);
-                               $it = new RecursiveIteratorIterator($it);
+                               $it = new RecursiveCompareDualIterator($it);
                        }
                        else
                        {
diff --git a/ext/spl/examples/recursivecomparedualiterator.inc b/ext/spl/examples/recursivecomparedualiterator.inc
new file mode 100755 (executable)
index 0000000..75265c1
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+/** @file recursivecomparedualiterator.inc
+ * @ingroup Examples
+ * @brief class DualIterator
+ * @author  Marcus Boerger
+ * @date    2003 - 2006
+ *
+ * SPL - Standard PHP Library
+ */
+
+/** @ingroup Examples
+ * @brief   Recursive comparison iterator for a RecursiveDualIterator
+ * @author  Marcus Boerger
+ * @version 1.0
+ */
+class RecursiveCompareDualIterator extends RecursiveIteratorIterator
+{
+       /** Used to keep end of recursion equality. That is en leaving a nesting
+        * level we need to check whether both child iterators are at their end.
+        */
+       protected $equal = false;
+
+       /** Construct from RecursiveDualIterator
+        *
+        * @param $it      RecursiveDualIterator
+        * @param $mode    should be LEAVES_ONLY
+        * @param $flags   should be 0
+        */
+       function __construct(RecursiveDualIterator $it, $mode = self::LEAVES_ONLY, $flags = 0)
+       {
+               parent::__construct($it);
+       }
+
+       /** Rewind iteration andcomparison process. Starting with $equal = true.
+        */     
+       function rewind()
+       {
+               $this->equal = true;
+               parent::rewind();
+       }
+
+       /** Calculate $equal
+        * @see $equal
+        */
+       function endChildren()
+       {
+               $this->equal &= !$this->getInnerIterator()->getLHS()->valid()
+                            && !$this->getInnerIterator()->getRHS()->valid();
+       }
+
+       /** @return whether both inner iterators are valid and have identical 
+        * current and key values or both are non valid.
+        */
+       function areIdentical()
+       {
+               return $this->equal && $this->getInnerIterator()->areIdentical();
+       }
+
+       /** @return whether both inner iterators are valid and have equal current 
+        * and key values or both are non valid.
+        */
+       function areEqual()
+       {
+               return $this->equal && $this->getInnerIterator()->areEqual();
+       }
+}
+
+?>
index 702e0cd745411414188d114e1a6cd37bc49aafbe..cfa3bccbbcdab212fcac3d812eb22a6669a7e70a 100755 (executable)
@@ -18,7 +18,7 @@ class RecursiveDualIterator extends DualIterator implements RecursiveIterator
 {
        private $ref;
 
-       /** construct iterator from two iterators
+       /** construct iterator from two RecursiveIterator instances
         *
         * @param lhs   Left  Hand Side Iterator
         * @param rhs   Right Hand Side Iterator
index 5577c4dc180581d5696636e585694187c70d2768..9150d76ae07e8d872dbde25586192898e6371e96 100755 (executable)
@@ -33,6 +33,7 @@ test(array(1,array(21,22),3), array(1,array(21,"22"),3), true);
 
 ?>
 ===DONE===
+<?php exit(0); ?>
 --EXPECT--
 bool(true)
 bool(false)