Ditto 4.13.1
 
Loading...
Searching...
No Matches
Differ.hpp
1#ifndef DITTO_DIFFER_H
2#define DITTO_DIFFER_H
3
4#include "QueryResult.hpp"
5
6#include <cstddef>
7#include <cstdint>
8#include <map>
9#include <memory>
10#include <set>
11#include <utility>
12
13namespace ditto {
14
18using IndexSet = std::set<std::size_t>;
19
26struct Diff {
27public:
33 struct Move {
37 std::size_t from;
38
42 std::size_t to;
43
47 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
48 Move(std::size_t from, std::size_t to) : from(from), to(to) {}
49
53 Move() : from(0), to(0) {}
54
55 Move(const Move &other) = default;
56 Move &operator=(const Move &other) = default;
57 Move(Move &&other) = default;
58 Move &operator=(Move &&other) = default;
59 ~Move() = default;
60
61 bool operator==(const Move &other) const {
62 return from == other.from && to == other.to;
63 }
64
65 bool operator!=(const Move &other) const { return !(*this == other); }
66
67 bool operator<(const Move &other) const {
68 return from < other.from || (from == other.from && to < other.to);
69 }
70 };
71
77
83
89
94 std::vector<Move> moves;
95
99 Diff() = default;
100
105 std::vector<Move> moves)
106 : insertions(std::move(insertions)), deletions(std::move(deletions)),
107 updates(std::move(updates)), moves(std::move(moves)) {}
108
110
114 explicit Diff(const nlohmann::json &json);
116
117 Diff(const Diff &other) = default;
118 Diff &operator=(const Diff &other) = default;
119 Diff(Diff &&other) = default;
120 Diff &operator=(Diff &&other) = default;
121 ~Diff() = default;
122
126 bool operator==(const Diff &other) const;
127
131 bool operator!=(const Diff &other) const;
132};
133
140class Differ {
141private:
142 std::shared_ptr<dittoffi_differ_t> ffi_differ;
143
144public:
149
150 ~Differ();
151
152 Differ(const Differ &) = delete;
153 Differ &operator=(const Differ &) = delete;
154 Differ(Differ &&) = default;
155 Differ &operator=(Differ &&) = default;
156
172 Diff diff(const std::vector<QueryResultItem> &items);
173};
174
175} // namespace ditto
176
177#endif
Diff diff(const std::vector< QueryResultItem > &items)
Calculate the diff of the provided items against the last set of items that were passed to this diffe...
Differ()
Constructor.
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
std::set< std::size_t > IndexSet
A set of indexes into a vector.
Definition Differ.hpp:18
Representation of a move from one index to another in a vector.
Definition Differ.hpp:33
std::size_t from
The index in the old array from which the item has been moved.
Definition Differ.hpp:37
std::size_t to
The index in the new array to which the item has been moved.
Definition Differ.hpp:42
Move()
Default constructor.
Definition Differ.hpp:53
Move(std::size_t from, std::size_t to)
Constructor with initial values.
Definition Differ.hpp:48
Represents differences between two arrays of items.
Definition Differ.hpp:26
IndexSet insertions
The set of indexes in the new array at which the new items have been inserted.
Definition Differ.hpp:76
Diff()=default
Default constructor.
IndexSet updates
The set of indexes in the new array at which the items have been updated.
Definition Differ.hpp:88
IndexSet deletions
The set of indexes in the old array at which the items have been deleted.
Definition Differ.hpp:82
std::vector< Move > moves
A set of objects each representing a move of an item from a particular index in the old array to a pa...
Definition Differ.hpp:94
Diff(IndexSet insertions, IndexSet deletions, IndexSet updates, std::vector< Move > moves)
Constructor with initial values.
Definition Differ.hpp:104
bool operator==(const Diff &other) const
Test for equality between two diffs.
bool operator!=(const Diff &other) const
Test for inequality between two diffs.