Skip to content

Commit

Permalink
PERF: Use std::unordered_map in itkContourExtractor2DImageFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leengit authored and dzenanz committed Mar 23, 2021
1 parent c9f07d9 commit 5e884ce
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Modules/Filtering/Path/include/itkContourExtractor2DImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,16 @@ class ITK_TEMPLATE_EXPORT ContourExtractor2DImageFilter
// remove contours from our list when they have been merged into
// another. Thus, we store an iterator pointing to the contour in the list.

struct VertexLess
struct VertexHash
{
inline bool
operator()(const VertexType & l, const VertexType & r) const noexcept
using CoordinateType = typename VertexType::CoordRepType;
inline std::size_t
operator()(const VertexType & v) const noexcept
{
return (l[0] < r[0]) || ((l[0] == r[0]) && (l[1] < r[1]));
return std::hash<CoordinateType>{}(v[0]) ^ (std::hash<CoordinateType>{}(v[1]) << 1);
}
};

// Note that we cannot use std::unordered_map for
// VertexToContourContainerIteratorMap (even though that is asymptotically
// faster) because our code relies on the continuing validity of iterators
// even after insert or erase commands.
using VertexToContourContainerIteratorMap = std::map<VertexType, ContourContainerIterator, VertexLess>;
using VertexToContourContainerIteratorMap = std::unordered_map<VertexType, ContourContainerIterator, VertexHash>;
using VertexToContourContainerIteratorMapIterator = typename VertexToContourContainerIteratorMap::iterator;
using VertexToContourContainerIteratorMapConstIterator = typename VertexToContourContainerIteratorMap::const_iterator;
using VertexToContourContainerIteratorMapKeyValuePair = typename VertexToContourContainerIteratorMap::value_type;
Expand Down

0 comments on commit 5e884ce

Please sign in to comment.