43 class Iterator :
public std::forward_iterator_tag {
46 std::pair<KeyType, std::ranges::subrange<std::ranges::iterator_t<std::vector<ValueType>>>>;
47 using difference_type = std::ptrdiff_t;
56 std::ranges::subrange<std::ranges::iterator_t<std::ranges::range_value_t<R>>>
original_data,
70 value_type operator*()
const {
74 checkOrInitInnerIterator();
75 return {inner_iterator_->first, std::ranges::subrange(inner_iterator_->second)};
78 Iterator& operator++() {
82 checkOrInitInnerIterator();
98 if (isEnd() &&
other.isEnd()) {
101 if (isEnd() ||
other.isEnd()) {
104 return inner_data_ ==
other.inner_data_ && inner_iterator_ ==
other.inner_iterator_;
111 void evaluate()
const {
112 inner_data_ = std::make_shared<std::unordered_map<KeyType, std::vector<ValueType>>>();
113 for (
const auto& [
key,
value] : original_data_) {
114 (*inner_data_)[
key].push_back(
value);
122 void waitOrEvaluate()
const {
124 std::shared_lock the_shared_lock(*inner_data_mutex_);
130 std::unique_lock the_unique_lock(*inner_data_mutex_);
138 void checkOrInitInnerIterator()
const {
139 if (!inner_iterator_init_) {
140 inner_iterator_ = std::ranges::begin(*inner_data_);
141 inner_iterator_init_ =
true;
146 return is_end_ || (inner_iterator_init_ && inner_iterator_ == std::ranges::end(*inner_data_));
151 mutable std::shared_ptr<std::unordered_map<KeyType, std::vector<ValueType>>> inner_data_{
154 mutable std::ranges::iterator_t<std::unordered_map<KeyType, std::vector<ValueType>>>
157 mutable bool inner_iterator_init_{
false};
159 mutable std::shared_ptr<std::shared_mutex> inner_data_mutex_{
nullptr};
160 std::ranges::subrange<std::ranges::iterator_t<std::ranges::range_value_t<R>>> original_data_;