diff options
author | Marcus Boerger <helly@php.net> | 2006-12-10 23:44:49 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2006-12-10 23:44:49 +0000 |
commit | 66525a739eb90df0e528317b703c01fe28f23953 (patch) | |
tree | ec0aff3841c6e1cb7e098fce66268e2e19a6af18 /ext | |
parent | e64cb1ae4d1be22d6844be9322fee4e7913b36b9 (diff) | |
download | php-git-66525a739eb90df0e528317b703c01fe28f23953.tar.gz |
- MFH Fix comparison of RecursiveDualIterators
Diffstat (limited to 'ext')
-rwxr-xr-x | ext/spl/examples/dualiterator.inc | 4 | ||||
-rwxr-xr-x | ext/spl/examples/recursivecomparedualiterator.inc | 69 | ||||
-rwxr-xr-x | ext/spl/examples/recursivedualiterator.inc | 2 | ||||
-rwxr-xr-x | ext/spl/examples/tests/dualiterator_001.phpt | 1 |
4 files changed, 73 insertions, 3 deletions
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 @@ +<?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(); + } +} + +?> 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=== +<?php exit(0); ?> --EXPECT-- bool(true) bool(false) |