Skip to content

Commit 8d41358

Browse files
add hash function for PartitionRegion
1 parent 2d1de0c commit 8d41358

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

vpr/src/base/partition_region.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,28 @@ PartitionRegion intersection(const PartitionRegion& cluster_pr, const PartitionR
7575
void update_cluster_part_reg(PartitionRegion& cluster_pr, const PartitionRegion& new_pr);
7676

7777
/**
78-
* @brief Get a PartitionRegion that covers the entire device.
78+
* @brief Get a PartitionRegion with a single Region that covers the entire device.
7979
*
8080
* @return A PartitionRegion that covers the whole device grid.
8181
*/
8282
const PartitionRegion& get_device_partition_region();
8383

84+
namespace std {
85+
template<>
86+
struct hash<PartitionRegion> {
87+
std::size_t operator()(const PartitionRegion& pr) const noexcept {
88+
const std::vector<Region>& regions = pr.get_regions();
89+
90+
std::size_t seed = std::hash<size_t>{}(regions.size());
91+
92+
for (const Region& region : regions) {
93+
vtr::hash_combine(seed, region);
94+
}
95+
96+
return seed;
97+
}
98+
};
99+
} // namespace std
100+
101+
84102
#endif /* PARTITION_REGIONS_H */

vpr/src/base/region.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Region intersection(const Region& r1, const Region& r2) {
8585
auto [intersect_layer_begin, intersect_layer_end] = std::make_pair(std::max(r1_layer_low, r2_layer_low),
8686
std::min(r1_layer_high, r2_layer_high));
8787

88+
// check that the give layer range start from a lower layer and end at a higher or the same layer
89+
// negative layer means that the given Region object is an empty region
8890
if (intersect_layer_begin > intersect_layer_end || intersect_layer_begin < 0 || intersect_layer_end < 0) {
8991
return {};
9092
}

0 commit comments

Comments
 (0)