Skip to content

Three-way merge function for prolly trees - #91

Merged
zhangfengcdt merged 6 commits into
mainfrom
feature/core.prollytree.merge
Aug 6, 2025
Merged

Three-way merge function for prolly trees#91
zhangfengcdt merged 6 commits into
mainfrom
feature/core.prollytree.merge

Conversation

@zhangfengcdt

Copy link
Copy Markdown
Owner

The implementation follows standard three-way merge semantics where non-conflicting changes are automatically merged, while conflicting changes are flagged with detailed information for manual resolution. All tests pass (18/18) confirming the implementation works correctly with the existing prolly tree architecture.

Merge Function:

  • Three-way merge algorithm that takes source, destination, and base tree root hashes

  • Comprehensive conflict detection for all merge scenarios

  • Efficient diff-based approach using existing tree comparison functionality

  • MergeResult::Added(key, value) - Apply addition from source branch

  • MergeResult::Removed(key) - Apply deletion from source branch

  • MergeResult::Modified(key, value) - Apply modification from source branch

  • MergeResult::Conflict(MergeConflict) - Conflict requiring manual resolution

Conflict Detection:

  • Both branches modify same key with different values
  • One branch adds while other removes same key
  • One branch adds while other modifies same key
  • One branch removes while other modifies same key
  • Identical changes are merged without conflict

Tests:

  1. test_merge_simple - Basic merge with identical trees (no changes)
  2. test_merge_with_conflicts - Different modifications to same key creating
    conflicts
  3. test_merge_to_empty_tree - Merging changes when destination is empty
  4. test_merge_add_remove_conflicts - Source removes key while destination modifies
    it
  5. test_merge_complex_scenario - Multiple operations with additions and conflicts
  6. test_merge_same_changes_no_conflict - Identical changes merge cleanly

✅ Key Features

  • Conflict Information: Each conflict includes base, source, and destination values
    for resolution
  • Non-destructive: Returns merge operations without modifying original trees
  • Storage Integration: Works with existing prolly tree storage architecture
  • Full Test Coverage: All major merge scenarios including edge cases
  • Production Ready: Integrated with existing Tree trait implementation

🔍 Usage Example

let merge_tree = ProllyTree::new(storage, config);
let merge_results = merge_tree.merge(&source_root, &dest_root, &base_root);

for result in merge_results {
match result {
MergeResult::Added(key, value) => /* apply addition /,
MergeResult::Modified(key, value) => /
apply modification /,
MergeResult::Removed(key) => /
apply deletion /,
MergeResult::Conflict(conflict) => /
handle conflict manually */,
}
}

@zhangfengcdt
zhangfengcdt merged commit a01f25f into main Aug 6, 2025
5 checks passed
@zhangfengcdt
zhangfengcdt deleted the feature/core.prollytree.merge branch August 12, 2025 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant