hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
set.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SET_HPP
7 #define IROHA_SET_HPP
8 
9 #include <unordered_set>
10 
11 namespace iroha {
21  template<typename Hasher,
22  typename Collection,
23  typename TargetType = typename Collection::value_type>
24  auto merge_unique(Collection left, Collection right) {
25  std::unordered_set<TargetType, Hasher>
26  unique_set(left.begin(), left.end());
27 
28  unique_set.insert(right.begin(), right.end());
29  return Collection(unique_set.begin(), unique_set.end());
30  }
31 
42  template<typename Set, typename Merge>
43  Set set_union(const Set &left, const Set &right, Merge &&merge) {
44  Set out;
45  out.insert(left.begin(), left.end());
46  for (auto &&tx : right) {
47  auto iter = out.find(tx);
48  if (iter != out.end()) {
49  merge(*iter, tx);
50  } else {
51  out.insert(tx);
52  }
53  }
54  return out;
55  }
56 
62  template<typename Set>
63  Set set_difference(const Set &left, const Set &right) {
64  Set out;
65  for (auto &&element : left) {
66  if (right.find(element) == right.end()) {
67  out.insert(element);
68  }
69  }
70  return out;
71  }
72 } // namespace iroha
73 #endif //IROHA_SET_HPP
Set set_difference(const Set &left, const Set &right)
Definition: set.hpp:63
Set set_union(const Set &left, const Set &right, Merge &&merge)
Definition: set.hpp:43
auto merge_unique(Collection left, Collection right)
Definition: set.hpp:24
Definition: block_query.hpp:16