Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Iterator.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2021 Reactive Markets Limited
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15#ifndef TOOLBOX_HDR_ITERATOR
16#define TOOLBOX_HDR_ITERATOR
17
18#include <toolbox/Config.h>
19
20#include <cstdint>
21
22namespace toolbox {
24inline namespace hdr {
25class Histogram;
26
29 public:
33 explicit Iterator(const Histogram& h) noexcept;
34 virtual ~Iterator();
35
36 // Copy.
37 Iterator(const Iterator&) = delete;
38 Iterator& operator=(const Iterator&) = delete;
39
40 // Move.
41 Iterator(Iterator&&) noexcept = default;
42 Iterator& operator=(Iterator&&) = delete;
43
45 std::int64_t count() const noexcept { return count_; }
47 std::int64_t cumulative_count() const noexcept { return cumulative_count_; }
49 std::int64_t value() const noexcept { return value_; }
50 std::int64_t highest_equivalent_value() const noexcept { return highest_equivalent_value_; }
51
56 bool next() noexcept { return do_next(); }
57
58 protected:
59 bool has_buckets() const noexcept;
60 bool has_next() const noexcept;
61 std::int64_t peek_next_value_from_index() const noexcept;
62 bool next_value_greater_than_reporting_level_upper_bound(
63 std::int64_t reporting_level_upper_bound) const noexcept;
64
65 bool basic_next() noexcept;
66 bool move_next() noexcept;
67 void update_iterated_values(std::int64_t new_value_iterated_to) noexcept;
68
69 virtual bool do_next() noexcept;
70
71 const Histogram& h_;
73 std::int32_t counts_index_;
75 std::int64_t total_count_;
76 std::int64_t count_;
77 std::int64_t cumulative_count_;
78 std::int64_t value_;
79 std::int64_t highest_equivalent_value_;
80 std::int64_t lowest_equivalent_value_;
81 std::int64_t median_equivalent_value_;
82 std::int64_t value_iterated_from_;
83 std::int64_t value_iterated_to_;
84};
85
88 public:
89 PercentileIterator(const Histogram& h, std::int32_t ticks_per_half_distance) noexcept;
90 ~PercentileIterator() override = default;
91
92 // Copy.
95
96 // Move.
98 PercentileIterator& operator=(PercentileIterator&&) = delete;
99
100 double percentile() const noexcept { return percentile_; }
101
102 protected:
103 bool do_next() noexcept override;
104
105 private:
106 bool seen_last_value_;
107 std::int32_t ticks_per_half_distance_;
108 double percentile_to_iterate_to_;
109 double percentile_;
110};
111
114 public:
115 // Copy.
118
119 // Move.
122
123 std::int64_t count_added_in_this_iteration_step() const noexcept
124 {
125 return count_added_in_this_iteration_step_;
126 }
127
128 protected:
129 explicit CountAddedIterator(const Histogram& h);
131
132 std::int64_t count_added_in_this_iteration_step_{0};
133};
134
137 public:
138 explicit RecordedIterator(const Histogram& h);
139 ~RecordedIterator() override = default;
140
141 // Copy.
144
145 // Move.
146 RecordedIterator(RecordedIterator&&) noexcept = default;
147 RecordedIterator& operator=(RecordedIterator&&) = delete;
148
149 protected:
150 bool do_next() noexcept override;
151};
152
155 public:
156 LinearIterator(const Histogram& h, std::int64_t value_units_per_bucket) noexcept;
157 ~LinearIterator() override = default;
158
159 // Copy.
162
163 // Move.
164 LinearIterator(LinearIterator&&) noexcept = default;
165 LinearIterator& operator=(LinearIterator&&) = delete;
166
167 protected:
168 bool do_next() noexcept override;
169
170 private:
171 std::int64_t value_units_per_bucket_;
172 std::int64_t next_value_reporting_level_;
173 std::int64_t next_value_reporting_level_lowest_equivalent_;
174};
175
178 public:
179 LogIterator(const Histogram& h, std::int64_t value_units_first_bucket,
180 double log_base) noexcept;
181 ~LogIterator() override = default;
182
183 // Copy.
184 LogIterator(const LogIterator&) = delete;
186
187 // Move.
188 LogIterator(LogIterator&&) noexcept = default;
189 LogIterator& operator=(LogIterator&&) = delete;
190
191 protected:
192 bool do_next() noexcept override;
193
194 private:
195 double log_base_;
196 std::int64_t next_value_reporting_level_;
197 std::int64_t next_value_reporting_level_lowest_equivalent_;
198};
199
200} // namespace hdr
201} // namespace toolbox
202
203#endif // TOOLBOX_HDR_ITERATOR
#define TOOLBOX_API
Definition Config.h:39
CountAddedIterator is a recorded value iterator.
Definition Iterator.hpp:113
CountAddedIterator(const CountAddedIterator &)=delete
CountAddedIterator(CountAddedIterator &&) noexcept=default
CountAddedIterator & operator=(const CountAddedIterator &)=delete
A High Dynamic Range (HDR) Histogram.
Definition Histogram.hpp:64
Iterator is the base iterator for all iterator types.
Definition Iterator.hpp:28
std::int64_t highest_equivalent_value() const noexcept
Definition Iterator.hpp:50
std::int64_t value() const noexcept
The current value based on counts_index.
Definition Iterator.hpp:49
std::int64_t cumulative_count() const noexcept
Sum of all of the counts up to and including the count at this index.
Definition Iterator.hpp:47
bool next() noexcept
Definition Iterator.hpp:56
Iterator(const Iterator &)=delete
Iterator & operator=(const Iterator &)=delete
Iterator(Iterator &&) noexcept=default
LinearIterator is a linear value iterator.
Definition Iterator.hpp:154
LinearIterator(const LinearIterator &)=delete
LinearIterator & operator=(const LinearIterator &)=delete
LinearIterator(const Histogram &h, std::int64_t value_units_per_bucket) noexcept
~LinearIterator() override=default
LinearIterator(LinearIterator &&) noexcept=default
LogIterator is a logarithmic value iterator.
Definition Iterator.hpp:177
LogIterator(LogIterator &&) noexcept=default
LogIterator & operator=(const LogIterator &)=delete
LogIterator(const Histogram &h, std::int64_t value_units_first_bucket, double log_base) noexcept
~LogIterator() override=default
LogIterator(const LogIterator &)=delete
PercentileIterator is a percentile iterator.
Definition Iterator.hpp:87
PercentileIterator(const Histogram &h, std::int32_t ticks_per_half_distance) noexcept
~PercentileIterator() override=default
PercentileIterator(PercentileIterator &&) noexcept=default
PercentileIterator(const PercentileIterator &)=delete
PercentileIterator & operator=(const PercentileIterator &)=delete
RecordedIterator is a recorded value iterator.
Definition Iterator.hpp:136
RecordedIterator(RecordedIterator &&) noexcept=default
RecordedIterator(const RecordedIterator &)=delete
RecordedIterator & operator=(const RecordedIterator &)=delete
~RecordedIterator() override=default
STL namespace.