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

Method update

sortedcontainers/sortedlist.py:1861–1898  ·  view source on GitHub ↗

Update sorted-key list by adding all values from `iterable`. Runtime complexity: `O(k*log(n))` -- approximate. >>> from operator import neg >>> skl = SortedKeyList(key=neg) >>> skl.update([3, 1, 2]) >>> skl SortedKeyList([3, 2, 1], key=<built-in func

(self, iterable)

Source from the content-addressed store, hash-verified

1859
1860
1861 def update(self, iterable):
1862 """Update sorted-key list by adding all values from `iterable`.
1863
1864 Runtime complexity: `O(k*log(n))` -- approximate.
1865
1866 >>> from operator import neg
1867 >>> skl = SortedKeyList(key=neg)
1868 >>> skl.update([3, 1, 2])
1869 >>> skl
1870 SortedKeyList([3, 2, 1], key=<built-in function neg>)
1871
1872 :param iterable: iterable of values to add
1873
1874 """
1875 _lists = self._lists
1876 _keys = self._keys
1877 _maxes = self._maxes
1878 values = sorted(iterable, key=self._key)
1879
1880 if _maxes:
1881 if len(values) * 4 >= self._len:
1882 _lists.append(values)
1883 values = reduce(iadd, _lists, [])
1884 values.sort(key=self._key)
1885 self._clear()
1886 else:
1887 _add = self.add
1888 for val in values:
1889 _add(val)
1890 return
1891
1892 _load = self._load
1893 _lists.extend(values[pos:(pos + _load)]
1894 for pos in range(0, len(values), _load))
1895 _keys.extend(list(map(self._key, _list)) for _list in _lists)
1896 _maxes.extend(sublist[-1] for sublist in _keys)
1897 self._len = len(values)
1898 del self._index[:]
1899
1900 _update = update
1901

Callers 15

test_updateFunction · 0.95
test_containsFunction · 0.95
test_getitemFunction · 0.95
test_isliceFunction · 0.95
test_bisect_leftFunction · 0.95
test_bisectFunction · 0.95
test_bisect_rightFunction · 0.95
test_bisect_key_leftFunction · 0.95
test_bisect_key_rightFunction · 0.95
test_bisect_keyFunction · 0.95
test_updateFunction · 0.95

Calls 2

appendMethod · 0.80
extendMethod · 0.80

Tested by 15

test_updateFunction · 0.76
test_containsFunction · 0.76
test_getitemFunction · 0.76
test_isliceFunction · 0.76
test_bisect_leftFunction · 0.76
test_bisectFunction · 0.76
test_bisect_rightFunction · 0.76
test_bisect_key_leftFunction · 0.76
test_bisect_key_rightFunction · 0.76
test_bisect_keyFunction · 0.76
test_updateFunction · 0.76