@@ -99,7 +99,7 @@ bool HierarchyItem::is_duplicate(std::shared_ptr<HierarchyItem> item) const
9999 if (s_priority_types.count (m_type) > 0 )
100100 return false ;
101101
102- if (m_name != item->m_name || m_country != item-> m_country || m_postcode != item->m_postcode )
102+ if (m_name != item->m_name || m_postcode != item->m_postcode )
103103 return false ;
104104
105105 if (m_type == item->m_type || same_starts_with (" building" , m_type, item->m_type )
@@ -149,29 +149,32 @@ void HierarchyItem::set_parent(hindex parent, bool force)
149149 // c->set_parent(m_id, force);
150150}
151151
152- void HierarchyItem::cleanup_children ()
152+ void HierarchyItem::cleanup_children (bool duplicate_only )
153153{
154154 // as a result of this run, children that are supposed to be kept are staying in children
155155 // property. all disposed ones are still pointed to via Hierarchy map, but should not be accessed
156156 // while moving along hierarchy for indexing or writing it
157- std::deque<std::shared_ptr<HierarchyItem> > children;
158- for (auto item : m_children)
159- {
160- item->cleanup_children ();
161- if (item->keep ())
162- children.push_back (item);
163- else
164- children.insert (children.end (), item->m_children .begin (), item->m_children .end ());
165- }
166- m_children = children;
157+ {
158+ std::deque<std::shared_ptr<HierarchyItem> > children;
159+ for (auto item : m_children)
160+ {
161+ item->cleanup_children ();
162+ if (item->keep ())
163+ children.push_back (item);
164+ else
165+ children.insert (children.end (), item->m_children .begin (), item->m_children .end ());
166+ }
167+ m_children = children;
168+ }
167169
168170 // check for duplicates
171+ bool had_duplicates = false ;
169172 for (size_t child_index = 0 ; child_index < m_children.size (); ++child_index)
170173 {
171174 std::shared_ptr<HierarchyItem> item = m_children[child_index];
175+ std::deque<std::shared_ptr<HierarchyItem> > children;
172176 std::deque<std::shared_ptr<HierarchyItem> > duplicates;
173177
174- children.clear ();
175178 children.insert (children.end (), m_children.begin (), m_children.begin () + child_index + 1 );
176179
177180 for (size_t i = child_index + 1 ; i < m_children.size (); ++i)
@@ -183,13 +186,17 @@ void HierarchyItem::cleanup_children()
183186 // merge duplicates
184187 for (auto &i : duplicates)
185188 {
189+ had_duplicates = true ;
186190 item->add_linked (i);
187191 item->m_children .insert (item->m_children .end (), i->m_children .begin (),
188192 i->m_children .end ());
189193 for (auto &i_children : i->m_children )
190194 i_children->set_parent (item->m_id , true );
191195 }
192196
197+ if (had_duplicates)
198+ item->cleanup_children (true );
199+
193200 m_children = children;
194201 }
195202
0 commit comments