Skip to content

Commit 2192a08

Browse files
committed
grt: Use custom hash function in AccessPointMap (cugr)
Avoid the clients having to hash themselves. Signed-off-by: Matt Liberty <[email protected]>
1 parent 1b1c673 commit 2192a08

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/grt/src/cugr/src/GridGraph.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ CostT GridGraph::getViaCost(const int layer_index, const PointT loc) const
354354

355355
GridGraph::AccessPointMap GridGraph::selectAccessPoints(const GRNet* net) const
356356
{
357-
AccessPointMap selected_access_points;
357+
PointHash hasher(y_size_);
358+
AccessPointMap selected_access_points(0, hasher);
358359
// cell hash (2d) -> access point, fixed layer interval
359360
selected_access_points.reserve(net->getNumPins());
360361
const auto& boundingBox = net->getBoundingBox();
@@ -392,11 +393,11 @@ GridGraph::AccessPointMap GridGraph::selectAccessPoints(const GRNet* net) const
392393
logger_->warn(utl::GRT, 274, "pin is hard to access.");
393394
}
394395
const PointT selectedPoint = accessPoints[bestIndex];
395-
const uint64_t hash = hashCell(selectedPoint.x(), selectedPoint.y());
396-
if (selected_access_points.find(hash) == selected_access_points.end()) {
397-
selected_access_points.emplace(hash, AccessPoint{selectedPoint, {}});
396+
const PointT key{selectedPoint.x(), selectedPoint.y()};
397+
if (selected_access_points.find(key) == selected_access_points.end()) {
398+
selected_access_points.emplace(key, AccessPoint{selectedPoint, {}});
398399
}
399-
IntervalT& fixedLayerInterval = selected_access_points[hash].layers;
400+
IntervalT& fixedLayerInterval = selected_access_points[key].layers;
400401
for (const auto& point : accessPoints) {
401402
if (point.x() == selectedPoint.x() && point.y() == selectedPoint.y()) {
402403
fixedLayerInterval.Update(point.getLayerIdx());

src/grt/src/cugr/src/GridGraph.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ class GRNet;
2121
template <typename Type>
2222
class GridGraphView;
2323

24+
class PointHash
25+
{
26+
public:
27+
PointHash(int y_size) : y_size_(y_size) {}
28+
29+
std::size_t operator()(const PointT& pt) const
30+
{
31+
return robin_hood::hash_int(pt.x() * y_size_ + pt.y());
32+
}
33+
34+
private:
35+
const uint64_t y_size_;
36+
};
37+
2438
struct GraphEdge
2539
{
2640
CapacityT getResource() const { return capacity - demand; }
@@ -53,10 +67,6 @@ class GridGraph
5367
return ((uint64_t) point.getLayerIdx() * x_size_ + point.x()) * y_size_
5468
+ point.y();
5569
};
56-
uint64_t hashCell(const int x, const int y) const
57-
{
58-
return (uint64_t) x * y_size_ + y;
59-
}
6070
int getGridline(const int dimension, const int index) const
6171
{
6272
return gridlines_[dimension][index];
@@ -81,7 +91,8 @@ class GridGraph
8191
IntervalT layers;
8292
};
8393

84-
using AccessPointMap = robin_hood::unordered_map<uint64_t, AccessPoint>;
94+
using AccessPointMap
95+
= robin_hood::unordered_map<PointT, AccessPoint, PointHash>;
8596
AccessPointMap selectAccessPoints(const GRNet* net) const;
8697

8798
// Methods for updating demands

src/grt/src/cugr/src/PatternRoute.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ void PatternRoute::constructSteinerTree()
136136
constructTree(current, curIndex, nextIndex);
137137
}
138138
// Set fixed layer interval
139-
const uint64_t hash
140-
= grid_graph_->hashCell(current->x(), current->y());
141-
if (selectedAccessPoints.find(hash) != selectedAccessPoints.end()) {
142-
current->setFixedLayers(selectedAccessPoints[hash].layers);
139+
const PointT current_pt{current->x(), current->y()};
140+
if (selectedAccessPoints.find(current_pt)
141+
!= selectedAccessPoints.end()) {
142+
current->setFixedLayers(selectedAccessPoints[current_pt].layers);
143143
}
144144
// Connect current to parent
145145
if (parent == nullptr) {

0 commit comments

Comments
 (0)