Skip to content

Commit d549d23

Browse files
committed
remove is_zero function from matrix interface
The `is_zero` shouldn't be part of the matrix type requirements, instead it should be a part of the scalar type requirements. Test: build Issue: saebyn#26 Signed-off-by: Gluttton <gluttton@ukr.net>
1 parent 0fb7c42 commit d549d23

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ The `munkres.h` header file contains the solver sources. The solver takes input
173173
The current implementation doesn't depend on a specific matrix type and can be used with an arbitrary data type that meets the following requirements:
174174
- the container type must implement the subscription operator `operator ()` that takes two parameters (row and column) and return a corresponding element of a matrix;
175175
- the container type must implement the `columns` and `rows` member functions that return matrix dimension;
176-
- the container type must implement the `is_zero` member function that allows testing a selected element is it zero;
177176
- the container type must implement the `begin` and `end` member functions that return appropriate iterators.
178177
179178
Also, the library doesn't require any specific type for a scalar element of the matrix, so any arbitrary data type can be used that meets the following requirements:
179+
- the element type must comparable with zero;
180180
- the element type must implement comparison operators (`<`, `>`);
181181
- the element type must implement addition and subtraction (`+`, `-`);
182182
- the element type must implement the assignment operator (`=`).

src/munkres-cpp/matrix_base.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#if !defined(__MUNKRES_CPP_MATRIX_BASE_H__)
2020
#define __MUNKRES_CPP_MATRIX_BASE_H__
2121

22-
#include <cmath>
2322
#include <iterator>
2423

2524

@@ -43,15 +42,6 @@ struct matrix_base
4342
// Default implementation.
4443
virtual ~matrix_base () = default;
4544

46-
// Implementation.
47-
template <typename V = value_type>
48-
constexpr typename std::enable_if<std::is_integral<V>::value, bool>::type
49-
is_zero (size_t row, size_t column) const {return operator () (row, column) == 0;}
50-
51-
template <typename V = value_type>
52-
constexpr typename std::enable_if<!std::is_integral<V>::value, bool>::type
53-
is_zero (size_t row, size_t column) const {return FP_ZERO == std::fpclassify (operator () (row, column) );}
54-
5545
// Allow to use standard algorithms.
5646
template <typename M>
5747
struct iterator : public std::iterator<std::input_iterator_tag, typename M::value_type>

src/munkres-cpp/munkres.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define _MUNKRES_H_
2222

2323
#include <algorithm>
24+
#include <cmath>
2425
#include <forward_list>
2526
#include <limits>
2627

@@ -29,6 +30,16 @@
2930
namespace munkres_cpp
3031
{
3132

33+
template <typename T>
34+
static constexpr typename std::enable_if<std::is_integral<T>::value, bool>::type
35+
is_zero (const T & v) {return v == 0;}
36+
37+
template <typename T>
38+
static constexpr typename std::enable_if<!std::is_integral<T>::value, bool>::type
39+
is_zero (const T & v) {return FP_ZERO == std::fpclassify (v);}
40+
41+
42+
3243
template<typename T, template <typename> class M>
3344
class Munkres
3445
{
@@ -93,7 +104,7 @@ bool Munkres<T, M>::find_uncovered_in_matrix (size_t & row, size_t & col) const
93104
if (!col_mask[col])
94105
for (row = 0; row < size; row++)
95106
if (!row_mask[row])
96-
if (matrix.is_zero (row, col) )
107+
if (is_zero (matrix (row, col) ) )
97108
return true;
98109

99110
return false;
@@ -106,7 +117,7 @@ int Munkres<T, M>::step1 ()
106117
{
107118
for (size_t row = 0; row < size; row++) {
108119
for (size_t col = 0; col < size; col++) {
109-
if (matrix.is_zero (row, col) ) {
120+
if (is_zero (matrix (row, col) ) ) {
110121
for (size_t nrow = 0; nrow < row; nrow++)
111122
if (STAR == mask_matrix (nrow, col) )
112123
goto next_column;
@@ -226,7 +237,7 @@ int Munkres<T, M>::step5 ()
226237
if (!col_mask[col])
227238
for (size_t row = 0; row < size; row++)
228239
if (!row_mask[row])
229-
if (h > matrix (row, col) && !matrix.is_zero (row, col) )
240+
if (h > matrix (row, col) && !is_zero (matrix (row, col) ) )
230241
h = matrix (row, col);
231242

232243
for (size_t row = 0; row < size; row++)

0 commit comments

Comments
 (0)