hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
collection_set.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_COLLECTION_SET_HPP
7 #define IROHA_COLLECTION_SET_HPP
8 
9 #include <shared_mutex>
10 #include <unordered_set>
11 
12 namespace iroha {
13  namespace set {
14 
23  template <typename Key,
24  typename Hash = std::hash<Key>,
25  typename KeyEqual = std::equal_to<Key>>
26  class CollectionSet {
27  public:
28  CollectionSet() = default;
29 
30  using value_type = Key;
31 
37  template <typename Collection>
38  void insertValues(Collection &&collection) {
39  std::lock_guard<std::shared_timed_mutex> lock(mutex_);
40  set_.insert(collection.begin(), collection.end());
41  }
42 
48  template <typename Collection>
49  void removeValues(Collection &&collection) {
50  std::lock_guard<std::shared_timed_mutex> lock(mutex_);
51  for (auto &&val : collection) {
52  set_.erase(val);
53  }
54  }
55 
61  template <typename Callable>
62  void forEach(Callable &&callable) const {
63  std::shared_lock<std::shared_timed_mutex> lock(mutex_);
64  std::for_each(set_.begin(), set_.end(), callable);
65  }
66 
67  private:
68  std::unordered_set<Key, Hash, KeyEqual> set_;
69  mutable std::shared_timed_mutex mutex_;
70  };
71  } // namespace set
72 } // namespace iroha
73 
74 #endif // IROHA_COLLECTION_SET_HPP
void insertValues(Collection &&collection)
Definition: collection_set.hpp:38
Key value_type
Definition: collection_set.hpp:30
Definition: collection_set.hpp:26
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) add_subdirectory(interactive) add_library(cli-flags_validators validators.cpp) target_link_libraries(cli-flags_validators gflags) add_library(client client.cpp impl/query_response_handler.cpp impl/transaction_response_handler.cpp impl/grpc_response_handler.cpp) target_link_libraries(client interactive_cli ed25519_crypto logger rapidjson pb_model_converters json_model_converters model_generators command_client query_client model_generators parser model) target_include_directories(client PUBLIC $
Definition: CMakeLists.txt:6
Definition: block_query.hpp:14
void removeValues(Collection &&collection)
Definition: collection_set.hpp:49
void forEach(Callable &&callable) const
Definition: collection_set.hpp:62