MCPcopy Index your code
hub / github.com/grantjenks/python-sortedcontainers / _expand

Method _expand

sortedcontainers/sortedlist.py:289–320  ·  view source on GitHub ↗

Split sublists with length greater than double the load-factor. Updates the index when the sublist length is less than double the load level. This requires incrementing the nodes in a traversal from the leaf node to the root. For an example traversal see ``SortedList

(self, pos)

Source from the content-addressed store, hash-verified

287
288
289 def _expand(self, pos):
290 """Split sublists with length greater than double the load-factor.
291
292 Updates the index when the sublist length is less than double the load
293 level. This requires incrementing the nodes in a traversal from the
294 leaf node to the root. For an example traversal see
295 ``SortedList._loc``.
296
297 """
298 _load = self._load
299 _lists = self._lists
300 _index = self._index
301
302 if len(_lists[pos]) > (_load << 1):
303 _maxes = self._maxes
304
305 _lists_pos = _lists[pos]
306 half = _lists_pos[_load:]
307 del _lists_pos[_load:]
308 _maxes[pos] = _lists_pos[-1]
309
310 _lists.insert(pos + 1, half)
311 _maxes.insert(pos + 1, half[-1])
312
313 del _index[:]
314 else:
315 if _index:
316 child = self._offset + pos
317 while child:
318 _index[child] += 1
319 child = (child - 1) >> 1
320 _index[0] += 1
321
322
323 def update(self, iterable):

Callers 2

addMethod · 0.95
_deleteMethod · 0.95

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected