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
Definition: block_query.hpp:16
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) add_library(server_runner server_runner.cpp) target_link_libraries(server_runner logger grpc++boost common) add_library(raw_block_loader impl/raw_block_loader.cpp) target_link_libraries(raw_block_loader shared_model_interfaces shared_model_proto_backend shared_model_stateless_validation logger) add_library(application application.cpp impl/on_demand_ordering_init.cpp impl/consensus_init.cpp impl/block_loader_init.cpp) target_link_libraries(application PRIVATE yac yac_transport PUBLIC logger logger_manager server_runner ametsuchi networking on_demand_ordering_service on_demand_ordering_service_transport_grpc on_demand_connection_manager on_demand_ordering_gate on_demand_common chain_validator stateful_validator processors ed25519_crypto simulator block_loader block_loader_service mst_processor torii_service pending_txs_storage common) add_executable(irohad irohad.cpp) target_link_libraries(irohad application raw_block_loader gflags rapidjson keys_manager common iroha_conf_loader logger logger_manager irohad_version) add_library(iroha_conf_loader iroha_conf_loader.cpp) target_link_libraries(iroha_conf_loader iroha_conf_literals logger_manager rapidjson) add_library(iroha_conf_literals iroha_conf_literals.cpp) add_dependencies(iroha_conf_literals logger) target_include_directories(iroha_conf_literals PUBLIC $
Definition: CMakeLists.txt:6
void removeValues(Collection &&collection)
Definition: collection_set.hpp:49
void forEach(Callable &&callable) const
Definition: collection_set.hpp:62