Skip to content

Commit

Permalink
collection_mutation: move collection_type_impl::merge to collection_m…
Browse files Browse the repository at this point in the history
…utation.hh.
  • Loading branch information
kbr-scylla committed Oct 25, 2019
1 parent a41277a commit 7e3bbe5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions collection_mutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,18 @@ collection_mutation collection_mutation_view_description::serialize(const abstra
return serialize_collection_mutation(type, tomb, boost::make_iterator_range(cells.begin(), cells.end()));
}

collection_mutation
collection_type_impl::merge(collection_mutation_view a, collection_mutation_view b) const {
return a.with_deserialized(*this, [&] (collection_mutation_view_description a_view) {
return b.with_deserialized(*this, [&] (collection_mutation_view_description b_view) {
collection_mutation merge(const abstract_type& type, collection_mutation_view a, collection_mutation_view b) {
return a.with_deserialized(type, [&] (collection_mutation_view_description a_view) {
return b.with_deserialized(type, [&] (collection_mutation_view_description b_view) {
assert(type.is_collection());
auto& ctype = static_cast<const collection_type_impl&>(type);

using element_type = std::pair<bytes_view, atomic_cell_view>;
auto key_type = name_comparator();
auto key_type = ctype.name_comparator();
auto compare = [key_type] (const element_type& e1, const element_type& e2) {
return key_type->less(e1.first, e2.first);
};
auto merge = [this] (const element_type& e1, const element_type& e2) {
auto merge = [] (const element_type& e1, const element_type& e2) {
// FIXME: use std::max()?
return std::make_pair(e1.first, compare_atomic_cell_for_merge(e1.second, e2.second) > 0 ? e1.second : e2.second);
};
Expand Down Expand Up @@ -254,7 +256,7 @@ collection_type_impl::merge(collection_mutation_view a, collection_mutation_view
merge);
merged.tomb = std::max(a_view.tomb, b_view.tomb);

return merged.serialize(*this);
return merged.serialize(type);
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions collection_mutation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ public:
collection_mutation(const abstract_type&, bytes_view);
operator collection_mutation_view() const;
};

collection_mutation merge(const abstract_type&, collection_mutation_view, collection_mutation_view);
3 changes: 1 addition & 2 deletions mutation_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,7 @@ apply_monotonically(const column_definition& def, cell_and_hash& dst,
dst.hash = std::move(src_hash);
}
} else {
auto ct = static_pointer_cast<const collection_type_impl>(def.type);
dst.cell = ct->merge(dst.cell.as_collection_mutation(), src.as_collection_mutation());
dst.cell = merge(*def.type, dst.cell.as_collection_mutation(), src.as_collection_mutation());
dst.hash = { };
}
}
Expand Down
1 change: 0 additions & 1 deletion types/collection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public:
static bytes pack(BytesViewIterator start, BytesViewIterator finish, int elements, cql_serialization_format sf);
virtual bytes to_value(collection_mutation_view_description mut, cql_serialization_format sf) const = 0;
bytes to_value(collection_mutation_view mut, cql_serialization_format sf) const;
collection_mutation merge(collection_mutation_view a, collection_mutation_view b) const;
collection_mutation difference(collection_mutation_view a, collection_mutation_view b) const;
virtual void serialize(const void* value, bytes::iterator& out, cql_serialization_format sf) const = 0;
virtual data_value deserialize(bytes_view v, cql_serialization_format sf) const = 0;
Expand Down

0 comments on commit 7e3bbe5

Please sign in to comment.