diff --git a/include/dindexer-machinery/set_listing.hpp b/include/dindexer-machinery/set_listing.hpp index 6692513..ea32ec3 100644 --- a/include/dindexer-machinery/set_listing.hpp +++ b/include/dindexer-machinery/set_listing.hpp @@ -50,21 +50,9 @@ namespace mchlib { reference dereference ( void ) const; bool is_end ( void ) const; - //There are three iterators and an offset because the first item - //could very well be detached from the rest of its siblings. For - //example "a", "b", "a/c", "a/d": when iterating on that sequence the - //expected outcome is "a", "a/c", "a/d". So in order to be able to - //iterate back and forward we need a "first" iterator so we can - //always get back to it whene we are decrementing an iterator to - //"a/c" for example. current is just the current iterator, and the - //offset is needed so we can tell if at any moment we are at - //first+offset and skip back to first instead of decrementing - //current. end is just there so we know when to stop advancing. - VecIterator m_first; VecIterator m_current; VecIterator m_end; std::unique_ptr m_base_path; - std::vector::difference_type m_second_offs; }; }; diff --git a/src/machinery/set_listing.cpp b/src/machinery/set_listing.cpp index 5c86b21..0937643 100644 --- a/src/machinery/set_listing.cpp +++ b/src/machinery/set_listing.cpp @@ -45,62 +45,42 @@ namespace mchlib { namespace implem { DirIterator::DirIterator (DirIterator&& parOther) : - m_first(std::move(parOther.m_first)), m_current(std::move(parOther.m_current)), m_end(std::move(parOther.m_end)), - m_base_path(std::move(parOther.m_base_path)), - m_second_offs(parOther.m_second_offs) + m_base_path(std::move(parOther.m_base_path)) { } DirIterator::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr&& parBasePath) : - m_first(parBegin), m_current(parBegin), m_end(parEnd), - m_base_path(std::move(parBasePath)), - m_second_offs(0) + m_base_path(std::move(parBasePath)) { assert(m_current == m_end or m_base_path->atom_count() == m_current->level); //Look for the point where the children of this entry starts - auto search_second = parBegin; while ( - search_second != m_end and ( - search_second->level == m_base_path->atom_count() or - *m_base_path != PathName(search_second->abs_path).pop_right() + m_current != m_end and ( + m_current->level == m_base_path->atom_count() or + *m_base_path != PathName(m_current->abs_path).pop_right() )) { - assert(search_second->level == m_base_path->atom_count()); - ++search_second; + //assert(m_current->level == m_base_path->atom_count()); + ++m_current; } - m_second_offs = std::distance(parBegin, search_second); } DirIterator::~DirIterator() noexcept { } void DirIterator::increment() { - if (m_current == m_first and m_second_offs > 1) { - m_current = m_first + m_second_offs; - } - else { - ++m_current; - } + ++m_current; } void DirIterator::decrement() { - if (m_current == m_first + m_second_offs) { - m_current = m_first; - } - else { - --m_current; - } + --m_current; } void DirIterator::advance (std::size_t parAdvance) { - if (m_current == m_first and parAdvance > 0) { - --parAdvance; - m_current = m_first + m_second_offs; - } m_current += parAdvance; } diff --git a/test/unit/test_diriterator.cpp b/test/unit/test_diriterator.cpp index f6d5789..b1e06bc 100644 --- a/test/unit/test_diriterator.cpp +++ b/test/unit/test_diriterator.cpp @@ -912,15 +912,17 @@ TEST(machinery, diriterator) { SetListing lst(std::move(test_data)); auto i = lst.begin(); - EXPECT_EQ("", i->abs_path); - - ++i; EXPECT_EQ("BestAndBest", i->abs_path); - auto view = SetListingView(i); - auto i2 = view.cbegin(); - EXPECT_EQ("BestAndBest/CD1", i2->abs_path); + { + auto view = SetListingView(i); + auto i2 = view.cbegin(); + EXPECT_EQ("BestAndBest/CD1", i2->abs_path); - ++i2; - EXPECT_EQ("BestAndBest/CD2", i2->abs_path); + ++i2; + EXPECT_EQ("BestAndBest/CD2", i2->abs_path); + } + + ++i; + EXPECT_EQ("City Hunter", i->abs_path); }