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

Method _delete

sortedcontainers/sortedlist.py:2054–2111  ·  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

2052
2053
2054 def _delete(self, pos, idx):
2055 """Delete value at the given `(pos, idx)`.
2056
2057 Combines lists that are less than half the load level.
2058
2059 Updates the index when the sublist length is more than half the load
2060 level. This requires decrementing the nodes in a traversal from the
2061 leaf node to the root. For an example traversal see
2062 ``SortedList._loc``.
2063
2064 :param int pos: lists index
2065 :param int idx: sublist index
2066
2067 """
2068 _lists = self._lists
2069 _keys = self._keys
2070 _maxes = self._maxes
2071 _index = self._index
2072 keys_pos = _keys[pos]
2073 lists_pos = _lists[pos]
2074
2075 del keys_pos[idx]
2076 del lists_pos[idx]
2077 self._len -= 1
2078
2079 len_keys_pos = len(keys_pos)
2080
2081 if len_keys_pos > (self._load >> 1):
2082 _maxes[pos] = keys_pos[-1]
2083
2084 if _index:
2085 child = self._offset + pos
2086 while child > 0:
2087 _index[child] -= 1
2088 child = (child - 1) >> 1
2089 _index[0] -= 1
2090 elif len(_keys) > 1:
2091 if not pos:
2092 pos += 1
2093
2094 prev = pos - 1
2095 _keys[prev].extend(_keys[pos])
2096 _lists[prev].extend(_lists[pos])
2097 _maxes[prev] = _keys[prev][-1]
2098
2099 del _lists[pos]
2100 del _keys[pos]
2101 del _maxes[pos]
2102 del _index[:]
2103
2104 self._expand(prev)
2105 elif len_keys_pos:
2106 _maxes[pos] = keys_pos[-1]
2107 else:
2108 del _lists[pos]
2109 del _keys[pos]
2110 del _maxes[pos]
2111 del _index[:]

Callers 2

discardMethod · 0.95
removeMethod · 0.95

Calls 2

_expandMethod · 0.95
extendMethod · 0.80

Tested by

no test coverage detected