Skip to content

Commit

Permalink
refactor(crdt): update template concepts and parameters
Browse files Browse the repository at this point in the history
Update ChangeComparatorConcept to ChangeComparator, add MergeRule concept,
and adjust template parameters in CRDT class and sync_nodes function
  • Loading branch information
sinkingsugar committed Oct 7, 2024
1 parent 708b8c0 commit 06858b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CompileFlags:
Add:
-std=c++20
10 changes: 5 additions & 5 deletions crdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <typename K, typename V> struct DefaultMergeRule {

// Define a concept for a custom change comparator
template <typename Comparator, typename K, typename V>
concept ChangeComparatorConcept = requires(Comparator c, const Change<K, V> &a, const Change<K, V> &b) {
concept ChangeComparator = requires(Comparator c, const Change<K, V> &a, const Change<K, V> &b) {
{ c(a, b) } -> std::convertible_to<bool>;
};

Expand Down Expand Up @@ -174,8 +174,8 @@ template <typename V> constexpr bool operator==(const Record<V> &lhs, const Reco
}

/// Represents the CRDT structure, generic over key (`K`) and value (`V`) types.
template <typename K, typename V, typename MergeRuleType = DefaultMergeRule<K, V>,
typename ChangeComparatorType = DefaultChangeComparator<K, V>, typename SortFunctionType = DefaultSort>
template <typename K, typename V, MergeRule<K, V> MergeRuleType = DefaultMergeRule<K, V>,
ChangeComparator<K, V> ChangeComparatorType = DefaultChangeComparator<K, V>, typename SortFunctionType = DefaultSort>
class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, ChangeComparatorType, SortFunctionType>> {
public:
// Create a new empty CRDT
Expand Down Expand Up @@ -825,8 +825,8 @@ class CRDT : public std::enable_shared_from_this<CRDT<K, V, MergeRuleType, Chang
///
/// Complexity: O(c + m), where c is the number of changes since last_db_version,
/// and m is the complexity of merge_changes
template <typename K, typename V, typename MergeRuleType = DefaultMergeRule<K, V>,
typename ChangeComparatorType = DefaultChangeComparator<K, V>, typename SortFunctionType = DefaultSort>
template <typename K, typename V, MergeRule<K, V> MergeRuleType = DefaultMergeRule<K, V>,
ChangeComparator<K, V> ChangeComparatorType = DefaultChangeComparator<K, V>, typename SortFunctionType = DefaultSort>
constexpr void sync_nodes(CRDT<K, V, MergeRuleType, ChangeComparatorType, SortFunctionType> &source,
CRDT<K, V, MergeRuleType, ChangeComparatorType, SortFunctionType> &target, uint64_t &last_db_version) {
auto changes = source.get_changes_since(last_db_version);
Expand Down

0 comments on commit 06858b7

Please sign in to comment.