From a63543589970e7718701fe87013709a34552592b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 23 Jan 2019 23:39:43 +0100 Subject: [PATCH] Moved some code --- src/db/db/dbHash.h | 76 ++++++++++++++++++++++++++++++++++++ src/db/db/dbHierProcessor.cc | 14 +++---- src/db/db/dbHierProcessor.h | 63 ------------------------------ 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/src/db/db/dbHash.h b/src/db/db/dbHash.h index ef46366d3..5f5ecb481 100644 --- a/src/db/db/dbHash.h +++ b/src/db/db/dbHash.h @@ -238,6 +238,18 @@ namespace std } }; + /** + * @brief A hash function for a displacement transformation + */ + template + struct hash > + { + size_t operator() (const db::disp_trans &t) const + { + return hfunc (t.disp ()); + } + }; + /** * @brief Hash value for a complex transformation */ @@ -295,6 +307,54 @@ namespace std } }; + /** + * @brief A hash function for a shape reference + */ + template + struct hash > + { + size_t operator() (const db::shape_ref &o) const + { + return hfunc (std::hash () (*o.ptr ()), std::hash () (o.trans ())); + } + }; + + /** + * @brief A hash function for a polygon reference + */ + template + struct hash > + { + size_t operator() (const db::polygon_ref &o) const + { + return std::hash > () (o); + } + }; + + /** + * @brief A hash function for a path reference + */ + template + struct hash > + { + size_t operator() (const db::path_ref &o) const + { + return std::hash > () (o); + } + }; + + /** + * @brief A hash function for a text reference + */ + template + struct hash > + { + size_t operator() (const db::text_ref &o) const + { + return std::hash > () (o); + } + }; + /** * @brief A hash value for a db::LayerProperties object */ @@ -328,6 +388,22 @@ namespace std return hfunc (hf2 (p.second), h); } }; + + /** + * @brief Generic hash for an unordered set + */ + template + struct hash > + { + size_t operator() (const std::unordered_set &o) const + { + size_t hf = 0; + for (typename std::unordered_set::const_iterator i = o.begin (); i != o.end (); ++i) { + hf = hfunc (hf, std::hash () (*i)); + } + return hf; + } + }; } #endif diff --git a/src/db/db/dbHierProcessor.cc b/src/db/db/dbHierProcessor.cc index c99b49440..537d52967 100644 --- a/src/db/db/dbHierProcessor.cc +++ b/src/db/db/dbHierProcessor.cc @@ -892,7 +892,7 @@ void LocalProcessor::compute_contexts (LocalProcessorContexts &contexts, } } -// @@@ can we shortcut this if interactions is empty? +// TODO: can we shortcut this if interactions is empty? { db::box_scanner2 scanner; InteractionRegistrationInst2Inst rec (mp_subject_layout, contexts.subject_layer (), mp_intruder_layout, contexts.intruder_layer (), dist, &interactions); @@ -941,7 +941,7 @@ void LocalProcessor::compute_contexts (LocalProcessorContexts &contexts, scanner.process (rec, dist, inst_bcs, inst_bci); } -// @@@ can we shortcut this if interactions is empty? +// TODO: can we shortcut this if interactions is empty? { db::box_scanner2 scanner; InteractionRegistrationInst2Shape rec (mp_subject_layout, contexts.subject_layer (), dist, &interactions); @@ -1143,7 +1143,7 @@ LocalProcessor::compute_local_cell (const LocalProcessorContexts &contexts, db:: scanner.insert (ref, id++); } -// @@@ TODO: can we confine this search to the subject's (sized) bounding box? +// TODO: TODO: can we confine this search to the subject's (sized) bounding box? for (std::unordered_set::const_iterator i = intruders.second.begin (); i != intruders.second.end (); ++i) { scanner.insert (i.operator-> (), interactions.next_id ()); } @@ -1161,13 +1161,13 @@ LocalProcessor::compute_local_cell (const LocalProcessorContexts &contexts, db:: scanner.insert1 (ref, id++); } -// @@@ TODO: can we confine this search to the subject's (sized) bounding box? +// TODO: can we confine this search to the subject's (sized) bounding box? for (std::unordered_set::const_iterator i = intruders.second.begin (); i != intruders.second.end (); ++i) { scanner.insert2 (i.operator-> (), interactions.next_id ()); } if (intruder_shapes) { -// @@@ TODO: can we confine this search to the subject's (sized) bounding box? +// TODO: can we confine this search to the subject's (sized) bounding box? for (db::Shapes::shape_iterator i = intruder_shapes->begin (polygon_ref_flags ()); !i.at_end (); ++i) { scanner.insert2 (i->basic_ptr (db::PolygonRef::tag ()), interactions.next_id ()); } @@ -1198,7 +1198,7 @@ LocalProcessor::compute_local_cell (const LocalProcessorContexts &contexts, db:: // interactions low in the hierarchy. } else if (intruder_cell) { -// @@@ TODO: can we confine this search to the subject's (sized) bounding box? +// TODO: can we confine this search to the subject's (sized) bounding box? for (db::Cell::const_iterator i = intruder_cell->begin (); !i.at_end (); ++i) { if (! inst_bci (i->cell_inst ()).empty ()) { scanner.insert2 (&i->cell_inst (), ++inst_id); @@ -1206,7 +1206,7 @@ LocalProcessor::compute_local_cell (const LocalProcessorContexts &contexts, db:: } } -// @@@ TODO: can we confine this search to the subject's (sized) bounding box? +// TODO: can we confine this search to the subject's (sized) bounding box? for (std::unordered_set::const_iterator i = intruders.first.begin (); i != intruders.first.end (); ++i) { if (! inst_bci (*i).empty ()) { scanner.insert2 (i.operator-> (), ++inst_id); diff --git a/src/db/db/dbHierProcessor.h b/src/db/db/dbHierProcessor.h index 5bf25384b..7b6cae0a0 100644 --- a/src/db/db/dbHierProcessor.h +++ b/src/db/db/dbHierProcessor.h @@ -39,69 +39,6 @@ #include "dbHash.h" -// @@@ should go into dbHash.h -namespace std -{ - template - struct hash > - { - size_t operator() (const db::disp_trans &t) const - { - return hfunc (t.disp ()); - } - }; - - template - struct hash > - { - size_t operator() (const db::shape_ref &o) const - { - return hfunc (std::hash () (*o.ptr ()), std::hash () (o.trans ())); - } - }; - - template - struct hash > - { - size_t operator() (const db::polygon_ref &o) const - { - return std::hash > () (o); - } - }; - - template - struct hash > - { - size_t operator() (const db::path_ref &o) const - { - return std::hash > () (o); - } - }; - - template - struct hash > - { - size_t operator() (const db::text_ref &o) const - { - return std::hash > () (o); - } - }; - - template - struct hash > - { - size_t operator() (const std::unordered_set &o) const - { - size_t hf = 0; - for (typename std::unordered_set::const_iterator i = o.begin (); i != o.end (); ++i) { - hf = hfunc (hf, std::hash () (*i)); - } - return hf; - } - }; -} - - namespace db {