classes/iterator/IndexIterator.php
private function iterateKeyReader()
    {
        $results = $this->index->getKeyReader()->readKeys(
            $this->offset,
            $this->direction,
            $this->parseHints
        );
        if (empty($results)) {
            return $results;
            
        }
        
        // reverse order if iterating backwards
        if ($this->direction == KeyReader::DIRECTION_BACKWARD) {
            // $results = array_reverse($results);
            
            // trim results to the offset and reverse the order
            $revertBackwardResults = array();
            foreach ($results as $result) {
                if ($result->getOffset() > $this->offset) {
                    break;
                    
                }
                array_unshift($revertBackwardResults, $result);
                
            }
            $results = $revertBackwardResults;

        }

        // shift offset
        $end = end($results);
        switch ($this->direction) {

            case KeyReader::DIRECTION_FORWARD:
                $this->setOffset($end->getOffset() + strlen($end->getData()));
                break;

            case KeyReader::DIRECTION_BACKWARD:
                $this->setOffset($end->getOffset() - 1);
                break;

            default:
                throw new \LogicException("invalid direction");

        }
        
        // remove duplicates (BACKWARD only)
        $this->avoidBackwardDuplicates($results);
        
        reset($results);
        return $results;
    }
private function iterateKeyReader()
    {
        $results = $this->index->getKeyReader()->readKeys(
            $this->offset,
            $this->direction,
            $this->parseHints
        );
        if (empty($results)) {
            return $results;
            
        }
        
        // reverse order if iterating backwards
        if ($this->direction == KeyReader::DIRECTION_BACKWARD) {
            // $results = array_reverse($results);
            
            // trim results to the offset and reverse the order
            $revertBackwardResults = array();
            foreach ($results as $result) {
                if ($result->getOffset() > $this->offset) {
                    break;
                    
                }
                array_unshift($revertBackwardResults, $result);
                
            }
            $results = $revertBackwardResults;

        }

        // shift offset
        $end = end($results);
        switch ($this->direction) {

            case KeyReader::DIRECTION_FORWARD:
                $this->setOffset($end->getOffset() + strlen($end->getData()));
                break;

            case KeyReader::DIRECTION_BACKWARD:
                $this->setOffset($end->getOffset() - 1);
                break;

            default:
                throw new \LogicException("invalid direction");

        }
        
        // remove duplicates (BACKWARD only)
        $this->avoidBackwardDuplicates($results);
        
        reset($results);
        return $results;
    }
private function iterateKeyReader ( ) { $ results = $ this -> index -> getKeyReader ( ) -> readKeys ( $ this -> offset , $ this -> direction , $ this -> parseHints ) ; if ( empty ( $ results ) ) { return $ results ; } // reverse order if iterating backwards if ( $ this -> direction == KeyReader :: DIRECTION_BACKWARD ) { // $results = array_reverse($results); // trim results to the offset and reverse the order $ revertBackwardResults = array ( ) ; foreach ( $ results as $ result ) { if ( $ result -> getOffset ( ) > $ this -> offset ) { break ; } array_unshift ( $ revertBackwardResults , $ result ) ; } $ results = $ revertBackwardResults ; } // shift offset $ end = end ( $ results ) ; switch ( $ this -> direction ) { case KeyReader :: DIRECTION_FORWARD : $ this -> setOffset ( $ end -> getOffset ( ) + strlen ( $ end -> getData ( ) ) ) ; break ; case KeyReader :: DIRECTION_BACKWARD : $ this -> setOffset ( $ end -> getOffset ( ) - 1 ) ; break ; default : throw new \ LogicException ( "invalid direction" ) ; } // remove duplicates (BACKWARD only) $ this -> avoidBackwardDuplicates ( $ results ) ; reset ( $ results ) ; return $ results ; }
Iterates in the index and shifts the offset

@return Array
Iterates in the index and shifts the offset