Skip to content

Commit

Permalink
feat(CRDT): Add copy constructor and assignment operator
Browse files Browse the repository at this point in the history
Implements a copy constructor and assignment operator for the CRDT
class, enabling shallow copying of CRDT objects. This enhances the
class's functionality and allows for more flexible usage in various
contexts.
  • Loading branch information
sinkingsugar committed Oct 8, 2024
1 parent 06858b7 commit ea40859
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 @@ -711,6 +711,29 @@ class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, Chang
return is_record_tombstoned(record_id, ignore_parent);
}

// Add this constructor to the CRDT class
CRDT(const CRDT &other)
: node_id_(other.node_id_), clock_(other.clock_), data_(other.data_), tombstones_(other.tombstones_),
parent_(other.parent_), base_version_(other.base_version_), merge_rule_(other.merge_rule_),
change_comparator_(other.change_comparator_), sort_func_(other.sort_func_) {
// Note: This creates a shallow copy of the parent pointer
}

CRDT &operator=(const CRDT &other) {
if (this != &other) {
node_id_ = other.node_id_;
clock_ = other.clock_;
data_ = other.data_;
tombstones_ = other.tombstones_;
parent_ = other.parent_;
base_version_ = other.base_version_;
merge_rule_ = other.merge_rule_;
change_comparator_ = other.change_comparator_;
sort_func_ = other.sort_func_;
}
return *this;
}

private:
CrdtNodeId node_id_;
LogicalClock clock_;
Expand Down

0 comments on commit ea40859

Please sign in to comment.