diff --git a/src/db/db/dbHierNetworkProcessor.cc b/src/db/db/dbHierNetworkProcessor.cc index 3ee81d50c..5261a708d 100644 --- a/src/db/db/dbHierNetworkProcessor.cc +++ b/src/db/db/dbHierNetworkProcessor.cc @@ -349,10 +349,11 @@ local_clusters::remove_cluster (typename local_cluster::id_type id) return; } - // TODO: get rid of this const_cast by providing "delete by index" - // m_clusters.erase (id - 1) + // TODO: this const_cast is required. But we know what we're doing ... + // NOTE: we cannot really delete a cluster as this would shift the indexes. So + // we just clear them. local_cluster *to_delete = const_cast *> (& m_clusters.objects ().item (id - 1)); - m_clusters.erase (m_clusters.iterator_from_pointer (to_delete)); + to_delete->clear (); m_needs_update = true; } @@ -370,7 +371,9 @@ local_clusters::join_cluster_with (typename local_cluster::id_type id, typ local_cluster *first = const_cast *> (& m_clusters.objects ().item (id - 1)); first->join_with (*with); - m_clusters.erase (m_clusters.iterator_from_pointer (with)); + // NOTE: we cannot really delete a cluster as this would shift the indexes. So + // we just clear them. + with->clear (); m_needs_update = true; } @@ -707,8 +710,8 @@ public: } typename std::set::const_iterator c = sc->begin (); - ++c; - for (typename std::set::const_iterator cc = c; cc != sc->end (); ++cc) { + typename std::set::const_iterator cc = c; + for (++cc; cc != sc->end (); ++cc) { mp_cell_clusters->join_cluster_with (*c, *cc); } @@ -1074,12 +1077,28 @@ hier_clusters::do_build (cell_clusters_box_converter &cbc, const db::Layou hc_receiver rec (layout, local, *this, cbc, conn); cell_inst_clusters_box_converter cibc (cbc); + // The box scanner needs pointers so we have to first store the instances + // delivered by the cell's iterator (which does not deliver real pointer). + + std::vector inst_storage; + + // TODO: there should be a cell.size () for this ... + size_t n = 0; + for (db::Cell::const_iterator inst = cell.begin (); ! inst.at_end (); ++inst) { + n += 1; + } + + inst_storage.reserve (n); + for (db::Cell::const_iterator inst = cell.begin (); ! inst.at_end (); ++inst) { + inst_storage.push_back (*inst); + } + // handle instance to instance connections { db::box_scanner bs; - for (db::Cell::const_iterator inst = cell.begin (); ! inst.at_end (); ++inst) { + for (std::vector::const_iterator inst = inst_storage.begin (); inst != inst_storage.end (); ++inst) { bs.insert (inst.operator-> (), 0); } @@ -1094,7 +1113,7 @@ hier_clusters::do_build (cell_clusters_box_converter &cbc, const db::Layou for (typename connected_clusters::const_iterator c = local.begin (); c != local.end (); ++c) { bs2.insert1 (c.operator-> (), 0); } - for (db::Cell::const_iterator inst = cell.begin (); ! inst.at_end (); ++inst) { + for (std::vector::const_iterator inst = inst_storage.begin (); inst != inst_storage.end (); ++inst) { bs2.insert2 (inst.operator-> (), 0); } diff --git a/src/db/unit_tests/dbHierNetworkProcessorTests.cc b/src/db/unit_tests/dbHierNetworkProcessorTests.cc index b28c7fee5..c18d6291e 100644 --- a/src/db/unit_tests/dbHierNetworkProcessorTests.cc +++ b/src/db/unit_tests/dbHierNetworkProcessorTests.cc @@ -516,8 +516,8 @@ static void run_hc_test (tl::TestBase *_this, const std::string &file, const std unsigned int lout = net_layers.back ().second; - db::Shapes &out = ly.cell (*ly.begin_top_down ()).shapes (lout); - copy_cluster_shapes (out, *ly.begin_top_down (), hc, *c, db::ICplxTrans (), conn); + db::Shapes &out = ly.cell (*td).shapes (lout); + copy_cluster_shapes (out, *td, hc, *c, db::ICplxTrans (), conn); db::Polygon::area_type area = 0; for (db::Shapes::shape_iterator s = out.begin (db::ShapeIterator::All); ! s.at_end (); ++s) { @@ -547,3 +547,8 @@ TEST(40_HierClusters) { run_hc_test (_this, "hc_test_l1.gds", "hc_test_au1.gds"); } + +TEST(41_HierClusters) +{ + run_hc_test (_this, "hc_test_l2.gds", "hc_test_au2.gds"); +} diff --git a/testdata/algo/hc_test_au2.gds b/testdata/algo/hc_test_au2.gds new file mode 100644 index 000000000..86ba92af2 Binary files /dev/null and b/testdata/algo/hc_test_au2.gds differ diff --git a/testdata/algo/hc_test_l2.gds b/testdata/algo/hc_test_l2.gds new file mode 100644 index 000000000..f876246b0 Binary files /dev/null and b/testdata/algo/hc_test_l2.gds differ