Skip to content

Commit d22b410

Browse files
committed
[XPTI] Universal ID changes to support key in std::map
+ Universal ID needs to be available for use as a key in std::map and this requires std::less understanding this type or the type supporting operator<(). Removing the std::less implementation as the object already supports operator<(). Add unit tests to see if the std::map insertions are ordered. Signed-off-by: Vasanth Tovinkere <[email protected]>
1 parent 5611466 commit d22b410

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

xpti/include/xpti_data_types.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ struct uid_t {
6262

6363
/// Specialize std::hash to support xpti::uid_t
6464
namespace std {
65-
template <>
66-
struct less<xpti::uid_t>
67-
: public binary_function<xpti::uid_t, xpti::uid_t, bool> {
68-
std::size_t operator()(const xpti::uid_t &lhs, const xpti::uid_t &rhs) const {
69-
if (lhs.p1 < rhs.p1)
70-
return true;
71-
if (lhs.p1 == rhs.p1 && lhs.p2 < rhs.p2)
72-
return true;
73-
if (lhs.p1 == rhs.p1 && lhs.p2 == rhs.p2 && lhs.p3 < rhs.p3)
74-
return true;
75-
return false;
76-
}
77-
};
7865
template <> struct hash<xpti::uid_t> {
7966
std::size_t operator()(const xpti::uid_t &key) const { return key.hash(); }
8067
};

xptifw/unit_test/xpti_correctness_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ TEST(xptiCorrectnessTest, xptiUniversalIDMapTest) {
374374
for (auto &e : MapTest) {
375375
EXPECT_EQ(e.first.hash(), e.second);
376376
}
377+
// Check if the IDs are in sorted order
378+
xpti::uid_t prev;
379+
for (auto &e : MapTest) {
380+
bool test = prev < e.first;
381+
EXPECT_EQ(test, true);
382+
}
377383
}
378384

379385
TEST(xptiCorrectnessTest, xptiUniversalIDUnorderedMapTest) {

0 commit comments

Comments
 (0)