Moved some code

This commit is contained in:
Matthias Koefferlein 2019-01-23 23:39:43 +01:00
parent 1cfa3251ce
commit a635435899
3 changed files with 83 additions and 70 deletions

View File

@ -238,6 +238,18 @@ namespace std
}
};
/**
* @brief A hash function for a displacement transformation
*/
template <class C>
struct hash <db::disp_trans<C> >
{
size_t operator() (const db::disp_trans<C> &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 <class Shape, class Trans>
struct hash<db::shape_ref<Shape, Trans> >
{
size_t operator() (const db::shape_ref<Shape, Trans> &o) const
{
return hfunc (std::hash<Shape> () (*o.ptr ()), std::hash<Trans> () (o.trans ()));
}
};
/**
* @brief A hash function for a polygon reference
*/
template <class Shape, class Trans>
struct hash<db::polygon_ref<Shape, Trans> >
{
size_t operator() (const db::polygon_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (o);
}
};
/**
* @brief A hash function for a path reference
*/
template <class Shape, class Trans>
struct hash<db::path_ref<Shape, Trans> >
{
size_t operator() (const db::path_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (o);
}
};
/**
* @brief A hash function for a text reference
*/
template <class Shape, class Trans>
struct hash<db::text_ref<Shape, Trans> >
{
size_t operator() (const db::text_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (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 <class T>
struct hash<std::unordered_set<T> >
{
size_t operator() (const std::unordered_set<T> &o) const
{
size_t hf = 0;
for (typename std::unordered_set<T>::const_iterator i = o.begin (); i != o.end (); ++i) {
hf = hfunc (hf, std::hash <T> () (*i));
}
return hf;
}
};
}
#endif

View File

@ -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<db::CellInstArray, int, db::CellInstArray, int> 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<db::CellInstArray, int, db::PolygonRef, int> 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<db::PolygonRef>::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<db::PolygonRef>::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<db::CellInstArray>::const_iterator i = intruders.first.begin (); i != intruders.first.end (); ++i) {
if (! inst_bci (*i).empty ()) {
scanner.insert2 (i.operator-> (), ++inst_id);

View File

@ -39,69 +39,6 @@
#include "dbHash.h"
// @@@ should go into dbHash.h
namespace std
{
template <class C>
struct hash <db::disp_trans<C> >
{
size_t operator() (const db::disp_trans<C> &t) const
{
return hfunc (t.disp ());
}
};
template <class Shape, class Trans>
struct hash<db::shape_ref<Shape, Trans> >
{
size_t operator() (const db::shape_ref<Shape, Trans> &o) const
{
return hfunc (std::hash<Shape> () (*o.ptr ()), std::hash<Trans> () (o.trans ()));
}
};
template <class Shape, class Trans>
struct hash<db::polygon_ref<Shape, Trans> >
{
size_t operator() (const db::polygon_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (o);
}
};
template <class Shape, class Trans>
struct hash<db::path_ref<Shape, Trans> >
{
size_t operator() (const db::path_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (o);
}
};
template <class Shape, class Trans>
struct hash<db::text_ref<Shape, Trans> >
{
size_t operator() (const db::text_ref<Shape, Trans> &o) const
{
return std::hash<db::shape_ref<Shape, Trans> > () (o);
}
};
template <class T>
struct hash<std::unordered_set<T> >
{
size_t operator() (const std::unordered_set<T> &o) const
{
size_t hf = 0;
for (typename std::unordered_set<T>::const_iterator i = o.begin (); i != o.end (); ++i) {
hf = hfunc (hf, std::hash <T> () (*i));
}
return hf;
}
};
}
namespace db
{