Skip to content

Commit

Permalink
Use spaceship everywhere. (eBay#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd authored and hkadayam committed Sep 27, 2023
1 parent 34abfd7 commit d487afd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/include/homeobject/pg_manager.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <compare>
#include <set>
#include <string>

Expand All @@ -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 >;
Expand All @@ -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 > {
Expand All @@ -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
4 changes: 4 additions & 0 deletions src/include/homeobject/shard_manager.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <compare>
#include <list>
#include <optional>

Expand Down Expand Up @@ -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 >;
Expand Down
1 change: 1 addition & 0 deletions src/lib/blob_route.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <compare>
#include <functional>

#include <boost/functional/hash.hpp>
Expand Down
3 changes: 0 additions & 3 deletions src/lib/homeobject_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d487afd

Please sign in to comment.