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

Method _delete

sortedcontainers/sortedlist.py:465–517  ·  view source on GitHub ↗

Delete value at the given `(pos, idx)`. Combines lists that are less than half the load level. Updates the index when the sublist length is more than half the load level. This requires decrementing the nodes in a traversal from the leaf node to the root. For an exam

(self, pos, idx)

Source from the content-addressed store, hash-verified

463
464
465 def _delete(self, pos, idx):
466 """Delete value at the given `(pos, idx)`.
467
468 Combines lists that are less than half the load level.
469
470 Updates the index when the sublist length is more than half the load
471 level. This requires decrementing the nodes in a traversal from the
472 leaf node to the root. For an example traversal see
473 ``SortedList._loc``.
474
475 :param int pos: lists index
476 :param int idx: sublist index
477
478 """
479 _lists = self._lists
480 _maxes = self._maxes
481 _index = self._index
482
483 _lists_pos = _lists[pos]
484
485 del _lists_pos[idx]
486 self._len -= 1
487
488 len_lists_pos = len(_lists_pos)
489
490 if len_lists_pos > (self._load >> 1):
491 _maxes[pos] = _lists_pos[-1]
492
493 if _index:
494 child = self._offset + pos
495 while child > 0:
496 _index[child] -= 1
497 child = (child - 1) >> 1
498 _index[0] -= 1
499 elif len(_lists) > 1:
500 if not pos:
501 pos += 1
502
503 prev = pos - 1
504 _lists[prev].extend(_lists[pos])
505 _maxes[prev] = _lists[prev][-1]
506
507 del _lists[pos]
508 del _maxes[pos]
509 del _index[:]
510
511 self._expand(prev)
512 elif len_lists_pos:
513 _maxes[pos] = _lists_pos[-1]
514 else:
515 del _lists[pos]
516 del _maxes[pos]
517 del _index[:]
518
519
520 def _loc(self, pos, idx):

Callers 4

discardMethod · 0.95
removeMethod · 0.95
__delitem__Method · 0.95
popMethod · 0.95

Calls 2

_expandMethod · 0.95
extendMethod · 0.80

Tested by

no test coverage detected