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

Method discard

sortedcontainers/sortedlist.py:1952–1998  ·  view source on GitHub ↗

Remove `value` from sorted-key list if it is a member. If `value` is not a member, do nothing. Runtime complexity: `O(log(n))` -- approximate. >>> from operator import neg >>> skl = SortedKeyList([5, 4, 3, 2, 1], key=neg) >>> skl.discard(1) >>> skl.

(self, value)

Source from the content-addressed store, hash-verified

1950
1951
1952 def discard(self, value):
1953 """Remove `value` from sorted-key list if it is a member.
1954
1955 If `value` is not a member, do nothing.
1956
1957 Runtime complexity: `O(log(n))` -- approximate.
1958
1959 >>> from operator import neg
1960 >>> skl = SortedKeyList([5, 4, 3, 2, 1], key=neg)
1961 >>> skl.discard(1)
1962 >>> skl.discard(0)
1963 >>> skl == [5, 4, 3, 2]
1964 True
1965
1966 :param value: `value` to discard from sorted-key list
1967
1968 """
1969 _maxes = self._maxes
1970
1971 if not _maxes:
1972 return
1973
1974 key = self._key(value)
1975 pos = bisect_left(_maxes, key)
1976
1977 if pos == len(_maxes):
1978 return
1979
1980 _lists = self._lists
1981 _keys = self._keys
1982 idx = bisect_left(_keys[pos], key)
1983 len_keys = len(_keys)
1984 len_sublist = len(_keys[pos])
1985
1986 while True:
1987 if _keys[pos][idx] != key:
1988 return
1989 if _lists[pos][idx] == value:
1990 self._delete(pos, idx)
1991 return
1992 idx += 1
1993 if idx == len_sublist:
1994 pos += 1
1995 if pos == len_keys:
1996 return
1997 len_sublist = len(_keys[pos])
1998 idx = 0
1999
2000
2001 def remove(self, value):

Callers 4

test_discardFunction · 0.95
test_removeFunction · 0.95
test_discardFunction · 0.95
test_removeFunction · 0.95

Calls 1

_deleteMethod · 0.95

Tested by 4

test_discardFunction · 0.76
test_removeFunction · 0.76
test_discardFunction · 0.76
test_removeFunction · 0.76