MCPcopy
hub / github.com/grantjenks/python-sortedcontainers / update

Method update

sortedcontainers/sortedlist.py:323–357  ·  view source on GitHub ↗

Update sorted list by adding all values from `iterable`. Runtime complexity: `O(k*log(n))` -- approximate. >>> sl = SortedList() >>> sl.update([3, 1, 2]) >>> sl SortedList([1, 2, 3]) :param iterable: iterable of values to add

(self, iterable)

Source from the content-addressed store, hash-verified

321
322
323 def update(self, iterable):
324 """Update sorted list by adding all values from `iterable`.
325
326 Runtime complexity: `O(k*log(n))` -- approximate.
327
328 >>> sl = SortedList()
329 >>> sl.update([3, 1, 2])
330 >>> sl
331 SortedList([1, 2, 3])
332
333 :param iterable: iterable of values to add
334
335 """
336 _lists = self._lists
337 _maxes = self._maxes
338 values = sorted(iterable)
339
340 if _maxes:
341 if len(values) * 4 >= self._len:
342 _lists.append(values)
343 values = reduce(iadd, _lists, [])
344 values.sort()
345 self._clear()
346 else:
347 _add = self.add
348 for val in values:
349 _add(val)
350 return
351
352 _load = self._load
353 _lists.extend(values[pos:(pos + _load)]
354 for pos in range(0, len(values), _load))
355 _maxes.extend(sublist[-1] for sublist in _lists)
356 self._len = len(values)
357 del self._index[:]
358
359 _update = update
360

Callers 7

test_updateFunction · 0.95
test_containsFunction · 0.95
test_isliceFunction · 0.95
test_irangeFunction · 0.95
test_bisect_leftFunction · 0.95
test_bisectFunction · 0.95
test_bisect_rightFunction · 0.95

Calls 2

appendMethod · 0.80
extendMethod · 0.80

Tested by 7

test_updateFunction · 0.76
test_containsFunction · 0.76
test_isliceFunction · 0.76
test_irangeFunction · 0.76
test_bisect_leftFunction · 0.76
test_bisectFunction · 0.76
test_bisect_rightFunction · 0.76