From d17cd366e91f32d0801a8d5eab51cb6818e7ca96 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 10 Dec 2006 23:44:35 +0000 Subject: [PATCH] - Fix comparison of RecursiveDualIterators --- ext/spl/examples/dualiterator.inc | 4 +- .../examples/recursivecomparedualiterator.inc | 69 +++++++++++++++++++ ext/spl/examples/recursivedualiterator.inc | 2 +- ext/spl/examples/tests/dualiterator_001.phpt | 1 + 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 ext/spl/examples/recursivecomparedualiterator.inc diff --git a/ext/spl/examples/dualiterator.inc b/ext/spl/examples/dualiterator.inc index 3db4487c4a..9d14328d74 100755 --- a/ext/spl/examples/dualiterator.inc +++ b/ext/spl/examples/dualiterator.inc @@ -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 index 0000000000..75265c1d58 --- /dev/null +++ b/ext/spl/examples/recursivecomparedualiterator.inc @@ -0,0 +1,69 @@ +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(); + } +} + +?> diff --git a/ext/spl/examples/recursivedualiterator.inc b/ext/spl/examples/recursivedualiterator.inc index 702e0cd745..cfa3bccbbc 100755 --- a/ext/spl/examples/recursivedualiterator.inc +++ b/ext/spl/examples/recursivedualiterator.inc @@ -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 diff --git a/ext/spl/examples/tests/dualiterator_001.phpt b/ext/spl/examples/tests/dualiterator_001.phpt index 5577c4dc18..9150d76ae0 100755 --- a/ext/spl/examples/tests/dualiterator_001.phpt +++ b/ext/spl/examples/tests/dualiterator_001.phpt @@ -33,6 +33,7 @@ test(array(1,array(21,22),3), array(1,array(21,"22"),3), true); ?> ===DONE=== + --EXPECT-- bool(true) bool(false) -- 2.40.0