MCPcopy Create free account
hub / github.com/apple/foundationdb / insert

Method insert

fdbclient/include/fdbclient/KeyRangeMap.h:201–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199
200template <class Val, class Metric, class MetricFunc>
201void CoalescedKeyRangeMap<Val, Metric, MetricFunc>::insert(const KeyRangeRef& keys, const Val& value) {
202 ASSERT(keys.end <= mapEnd);
203
204 if (keys.empty())
205 return;
206
207 auto begin = RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::map.lower_bound(keys.begin);
208 auto end = RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::map.lower_bound(keys.end);
209 bool insertEnd = false;
210 bool insertBegin = false;
211 Val endVal;
212
213 if (keys.end != mapEnd) {
214 if (end->key != keys.end) {
215 auto before_end = end;
216 before_end.decrementNonEnd();
217 if (value != before_end->value) {
218 insertEnd = true;
219 endVal = before_end->value;
220 }
221 }
222
223 if (!insertEnd && end->value == value && end->key != mapEnd) {
224 ++end;
225 }
226 }
227
228 if (keys.begin == allKeys.begin) {
229 insertBegin = true;
230 } else {
231 auto before_begin = begin;
232 before_begin.decrementNonEnd();
233 if (before_begin->value != value)
234 insertBegin = true;
235 }
236
237 RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::map.erase(begin, end);
238 if (insertEnd) {
239 MapPair<Key, Val> p(keys.end, endVal);
240 RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::map.insert(
241 p, true, RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::mf(p));
242 }
243 if (insertBegin) {
244 MapPair<Key, Val> p(keys.begin, value);
245 RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::map.insert(
246 p, true, RangeMap<Key, Val, KeyRangeRef, Metric, MetricFunc>::mf(p));
247 }
248}
249
250template <class Val, class Metric, class MetricFunc>
251void CoalescedKeyRangeMap<Val, Metric, MetricFunc>::insert(const KeyRef& key, const Val& value) {

Calls 6

equalsKeyAfterFunction · 0.85
decrementNonEndMethod · 0.80
keyAfterFunction · 0.70
emptyMethod · 0.45
lower_boundMethod · 0.45
eraseMethod · 0.45

Tested by 4

commitImplMethod · 0.36
setMethod · 0.36
clearMethod · 0.36
getRangeAsyncActorMethod · 0.36