Skip to content

Commit

Permalink
feat(CRDT): Add move constructor and assignment operator
Browse files Browse the repository at this point in the history
Implements move semantics for CRDT class to improve performance
and resource management when transferring ownership of CRDT objects
  • Loading branch information
sinkingsugar committed Oct 10, 2024
1 parent a43ebc3 commit 67bd7e4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,29 @@ class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, Chang
return *this;
}

// Move constructor
CRDT(CRDT &&other) noexcept
: node_id_(other.node_id_), clock_(std::move(other.clock_)), data_(std::move(other.data_)),
tombstones_(std::move(other.tombstones_)), parent_(std::move(other.parent_)), base_version_(other.base_version_),
merge_rule_(std::move(other.merge_rule_)), change_comparator_(std::move(other.change_comparator_)),
sort_func_(std::move(other.sort_func_)) {}

// Move assignment operator
CRDT &operator=(CRDT &&other) noexcept {
if (this != &other) {
node_id_ = other.node_id_;
clock_ = std::move(other.clock_);
data_ = std::move(other.data_);
tombstones_ = std::move(other.tombstones_);
parent_ = std::move(other.parent_);
base_version_ = other.base_version_;
merge_rule_ = std::move(other.merge_rule_);
change_comparator_ = std::move(other.change_comparator_);
sort_func_ = std::move(other.sort_func_);
}
return *this;
}

private:
CrdtNodeId node_id_;
LogicalClock clock_;
Expand Down

0 comments on commit 67bd7e4

Please sign in to comment.