From d487afd6cd3abb26efb0e8976a8583faa9ca274f Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Mon, 25 Sep 2023 09:04:52 -0700 Subject: [PATCH] Use spaceship everywhere. (#69) --- src/include/homeobject/pg_manager.hpp | 12 +++++++++--- src/include/homeobject/shard_manager.hpp | 4 ++++ src/lib/blob_route.hpp | 1 + src/lib/homeobject_impl.hpp | 3 --- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/include/homeobject/pg_manager.hpp b/src/include/homeobject/pg_manager.hpp index 9fc3ce0f..df416ab1 100644 --- a/src/include/homeobject/pg_manager.hpp +++ b/src/include/homeobject/pg_manager.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -17,6 +18,11 @@ struct PGMember { peer_id_t id; std::string name; int32_t priority{0}; // <0 (Arbiter), ==0 (Follower), >0 (F|Leader) + + auto operator<=>(PGMember const& rhs) const { + return boost::uuids::hash_value(id) <=> boost::uuids::hash_value(rhs.id); + } + auto operator==(PGMember const& rhs) const { return id == rhs.id; } }; using MemberSet = std::set< PGMember >; @@ -26,6 +32,9 @@ struct PGInfo { pg_id_t id; mutable MemberSet members; peer_id_t replica_set_uuid; + + auto operator<=>(PGInfo const& rhs) const { return id <=> rhs.id; } + auto operator==(PGInfo const& rhs) const { return id == rhs.id; } }; class PGManager : public Manager< PGError > { @@ -34,7 +43,4 @@ class PGManager : public Manager< PGError > { virtual NullAsyncResult replace_member(pg_id_t id, peer_id_t const& old_member, PGMember const& new_member) = 0; }; -inline bool operator<(homeobject::PGMember const& lhs, homeobject::PGMember const& rhs) { return lhs.id < rhs.id; } -inline bool operator<(homeobject::PGInfo const& lhs, homeobject::PGInfo const& rhs) { return lhs.id < rhs.id; } - } // namespace homeobject diff --git a/src/include/homeobject/shard_manager.hpp b/src/include/homeobject/shard_manager.hpp index 2b964f4c..223d5ea8 100644 --- a/src/include/homeobject/shard_manager.hpp +++ b/src/include/homeobject/shard_manager.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -26,6 +27,9 @@ struct ShardInfo { uint64_t total_capacity_bytes; uint64_t deleted_capacity_bytes; std::optional< peer_id_t > current_leader{std::nullopt}; + + auto operator<=>(ShardInfo const& rhs) const { return id <=> rhs.id; } + auto operator==(ShardInfo const& rhs) const { return id == rhs.id; } }; using InfoList = std::list< ShardInfo >; diff --git a/src/lib/blob_route.hpp b/src/lib/blob_route.hpp index 20e58426..e8bd47db 100644 --- a/src/lib/blob_route.hpp +++ b/src/lib/blob_route.hpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/lib/homeobject_impl.hpp b/src/lib/homeobject_impl.hpp index bc078ed2..d75e0068 100644 --- a/src/lib/homeobject_impl.hpp +++ b/src/lib/homeobject_impl.hpp @@ -21,9 +21,6 @@ inline shard_id_t make_new_shard_id(pg_id_t pg, shard_id_t next_shard) { return ((uint64_t)pg << shard_width) | next_shard; } -inline bool operator<(ShardInfo const& lhs, ShardInfo const& rhs) { return lhs.id < rhs.id; } -inline bool operator==(ShardInfo const& lhs, ShardInfo const& rhs) { return lhs.id == rhs.id; } - struct Shard { explicit Shard(ShardInfo info) : info(std::move(info)) {} ShardInfo info;