diff --git a/dccrg.hpp b/dccrg.hpp index a9edc5e..f810a75 100644 --- a/dccrg.hpp +++ b/dccrg.hpp @@ -4330,6 +4330,7 @@ template < if given error_cell. */ // TODO: make private? + // TODO: should same neighbor appear several times in returned list? std::vector< std::pair< uint64_t, @@ -7365,10 +7366,18 @@ template < uint64_t id = error_cell; Cell_Data* data = nullptr; Iterator_Storage - //! iterator to cells considered as neighbor by this cell + /*! + iterator to cells considered as neighbor by this cell, + may (and probably does) overlap with neighbors_to + */ neighbors_of, - //! iterator to cells that consider this one as neighbor - neighbors_to; + /*! + iterator to cells that consider this one as neighbor, + may (and probably does) overlap with neighbors_of + */ + neighbors_to, + //! iterates over both neighbors_of and neighbors_to + all_neighbors; friend bool operator < (const Cells_Item& a, const Cells_Item& b) { @@ -11573,10 +11582,12 @@ template < } for (size_t i = 0; i < cells.size(); i++) { - cells[i].neighbors_of.begin_ = - cells[i].neighbors_of.end_ = - cells[i].neighbors_to.begin_ = - cells[i].neighbors_to.end_ = neighbors.cbegin(); + cells[i].neighbors_of.begin_ = + cells[i].neighbors_of.end_ = + cells[i].neighbors_to.begin_ = + cells[i].neighbors_to.end_ = + cells[i].all_neighbors.begin_ = + cells[i].all_neighbors.end_ = neighbors.cbegin(); std::advance( cells[i].neighbors_of.begin_, nr_neighbors[i][0] @@ -11593,6 +11604,14 @@ template < cells[i].neighbors_to.end_, nr_neighbors[i][0] + nr_neighbors[i][1] + nr_neighbors[i][2] + nr_neighbors[i][3] ); + std::advance( + cells[i].all_neighbors.begin_, + nr_neighbors[i][0] + ); + std::advance( + cells[i].all_neighbors.end_, + nr_neighbors[i][0] + nr_neighbors[i][1] + nr_neighbors[i][2] + nr_neighbors[i][3] + ); } // update iterators diff --git a/tests/iterators/project_makefile b/tests/iterators/project_makefile index 3393494..2d8035d 100644 --- a/tests/iterators/project_makefile +++ b/tests/iterators/project_makefile @@ -64,7 +64,7 @@ tests/iterators/test1.mtst: \ tests/iterators/test2.exe: \ tests/iterators/test2.cpp \ $(TESTS_ITERATORS_COMMON_DEPS) - $(TESTS_ITERATORS_COMPILE_COMMAND) + $(TESTS_ITERATORS_COMPILE_COMMAND) -std=c++14 tests/iterators/test2.tst: \ tests/iterators/test2.exe diff --git a/tests/iterators/test2.cpp b/tests/iterators/test2.cpp index 32609ec..98cefb8 100644 --- a/tests/iterators/test2.cpp +++ b/tests/iterators/test2.cpp @@ -107,6 +107,21 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } + // check all_neighbors + if (not std::equal( + cell.neighbors_of.begin(), + cell.neighbors_to.end(), + cell.all_neighbors.begin(), + [](const auto& first, const auto& second){ + return first.id == second.id; + } + )) { + cerr << __FILE__ "(" << __LINE__ << "): " + << "all_neighbors of cell " << cell.id + << " doesn't equal neighbors_of + _to" << endl; + return EXIT_FAILURE; + } + // check offset for (const auto& neighbor: cell.neighbors_of) { const int ref_diff = (neighbor.id - cell.id) * grid.mapping.get_cell_length_in_indices(cell.id);