89 void update(T left, T right, V value) {
92 auto it = map.find(left);
93 if (it != map.end()) {
98 auto _value = update_policy(p.second, value);
102 if (p.first.right > right) {
107 if (_value != p.second) {
108 if (p.first.left != left) {
109 map.insert({
Interval<T>{p.first.left, left}, p.second});
112 map.insert({
Interval<T>{right, p.first.right}, p.second});
114 map.insert({
Interval<T>{p.first.left, p.first.right}, _value});
121 if (_value != p.second) {
122 if (p.first.left != left) {
123 map.insert({
Interval<T>{p.first.left, left}, p.second});
125 map.insert({
Interval<T>{left, p.first.right}, _value});
127 map.insert({
Interval<T>{p.first.left, p.first.right}, _value});
130 if (p.first.right != right) {
132 update(p.first.right, right, value);
141 if (right - 1 > right) {
142 throw std::overflow_error(
"right underflows.");
144 it = map.find(right - 1);
146 if (it != map.end()) {
149 assert(left < p.first.left);
150 assert(right > p.first.left);
151 assert(right <= p.first.right);
153 update(left, p.first.left, value);
155 auto _value = update_policy(p.second, value);
160 if (_value == p.second) {
161 map.insert({
Interval<T>{p.first.left, p.first.right}, _value});
163 map.insert({
Interval<T>{p.first.left, right}, _value});
164 if (right < p.first.right) {
165 map.insert({
Interval<T>{right, p.first.right}, p.second});
174 it = map.lower_bound(left);
175 if (it == map.end()) {
180 assert(left < p.first.left);
183 if (right <= p.first.left) {
188 map.insert({
Interval<T>{left, p.first.left}, value});
190 update(p.first.left, right, value);
215 if (map.size() < 2) {
218 auto it = map.begin();
219 auto right = it->first.right;
220 auto value = it->second;
221 auto next_it = std::next(it);
224 if (right == next_it->first.left && value == next_it->second) {
225 auto new_left = it->first.left;
226 auto new_right = next_it->first.right;
229 auto [new_it, success] = map.insert({
Interval<T>{new_left, new_right}, value});
233 right = it->first.right;
235 next_it = std::next(it);
238 right = it->first.right;
240 next_it = std::next(it);
242 }
while (next_it != map.end());
244 assert(no_fragmentation());
254 std::vector<std::tuple<T, T, V> > intervals;
255 intervals.reserve(map.size());
257 for (
const auto &entry: map) {
258 intervals.emplace_back(entry.first.left, entry.first.right, entry.second);