Skip to content

Commit ac39401

Browse files
committed
planner: add span_t == op
Problem: `span_t` equality testing should be done via operator overloading, not in a `planner` member function. Add a `span_t` struct equality comparison operator.
1 parent 8b93e51 commit ac39401

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

resource/planner/c++/planner.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ extern "C" {
2121
#include "planner.hpp"
2222

2323

24+
/****************************************************************************
25+
* *
26+
* Public Span_t Methods *
27+
* *
28+
****************************************************************************/
29+
30+
bool span_t::operator== (const span_t &o) const
31+
{
32+
if (start != o.start)
33+
return false;
34+
if (last != o.last)
35+
return false;
36+
if (span_id != o.span_id)
37+
return false;
38+
if (planned != o.planned)
39+
return false;
40+
if (in_system != o.in_system)
41+
return false;
42+
if ((*(start_p) != *(o.start_p)))
43+
return false;
44+
if ((*(last_p) != *(o.last_p)))
45+
return false;
46+
47+
return true;
48+
}
49+
50+
bool span_t::operator!= (const span_t &o) const
51+
{
52+
return !operator == (o);
53+
}
54+
2455
/****************************************************************************
2556
* *
2657
* Public Planner Methods *
@@ -441,21 +472,8 @@ bool planner::span_lookups_equal (const planner &o) const
441472
return false;
442473
if (this_it.first != other->first)
443474
return false;
444-
if (this_it.second->start != other->second->start)
445-
return false;
446-
if (this_it.second->last != other->second->last)
447-
return false;
448-
if (this_it.second->span_id != other->second->span_id)
449-
return false;
450-
if (this_it.second->planned != other->second->planned)
451-
return false;
452-
if (this_it.second->in_system != other->second->in_system)
453-
return false;
454-
if (this_it.second->in_system != other->second->in_system)
455-
return false;
456-
if (*(this_it.second->start_p) != *(other->second->start_p))
457-
return false;
458-
if (*(this_it.second->last_p) != *(other->second->last_p))
475+
// Compare span_t
476+
if (*(this_it.second) != *(other->second))
459477
return false;
460478
}
461479
}

resource/planner/c++/planner.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct request_t {
2323
/*! Node in a span interval tree to enable fast retrieval of intercepting spans.
2424
*/
2525
struct span_t {
26+
bool operator== (const span_t &o) const;
27+
bool operator!= (const span_t &o) const;
28+
2629
int64_t start; /* start time of the span */
2730
int64_t last; /* end time of the span */
2831
int64_t span_id; /* unique span id */

0 commit comments

Comments
 (0)