| 124 | } |
| 125 | |
| 126 | void RangeCursor::forEachChunk(std::function<void(const ChunkRowRange&)> callback) { |
| 127 | for (const TopicChunk& chunk : *chunks_) { |
| 128 | // No early break: chunk ranges may overlap, so a later chunk can still |
| 129 | // intersect the query range even after one that lies past it. |
| 130 | if (chunk.stats.row_count == 0 || chunk.stats.t_max < t_min_ || chunk.stats.t_min > t_max_) { |
| 131 | continue; |
| 132 | } |
| 133 | const auto ts_begin = chunk.timestamps.begin(); |
| 134 | const auto ts_end = ts_begin + static_cast<std::ptrdiff_t>(chunk.stats.row_count); |
| 135 | const auto first_it = std::lower_bound(ts_begin, ts_end, t_min_); |
| 136 | const auto end_it = std::upper_bound(first_it, ts_end, t_max_); |
| 137 | if (first_it != end_it) { |
| 138 | callback( |
| 139 | ChunkRowRange{ |
| 140 | &chunk, static_cast<std::size_t>(first_it - ts_begin), static_cast<std::size_t>(end_it - ts_begin)}); |
| 141 | } |
| 142 | } |
| 143 | // Mark cursor exhausted |
| 144 | frontiers_.clear(); |
| 145 | } |
| 146 | |
| 147 | void RangeCursor::initFrontiers() { |
| 148 | const auto& chunks = *chunks_; |