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

Method discard

sortedcontainers/sortedlist.py:393–423  ·  view source on GitHub ↗

Remove `value` from sorted list if it is a member. If `value` is not a member, do nothing. Runtime complexity: `O(log(n))` -- approximate. >>> sl = SortedList([1, 2, 3, 4, 5]) >>> sl.discard(5) >>> sl.discard(0) >>> sl == [1, 2, 3, 4] True

(self, value)

Source from the content-addressed store, hash-verified

391
392
393 def discard(self, value):
394 """Remove `value` from sorted list if it is a member.
395
396 If `value` is not a member, do nothing.
397
398 Runtime complexity: `O(log(n))` -- approximate.
399
400 >>> sl = SortedList([1, 2, 3, 4, 5])
401 >>> sl.discard(5)
402 >>> sl.discard(0)
403 >>> sl == [1, 2, 3, 4]
404 True
405
406 :param value: `value` to discard from sorted list
407
408 """
409 _maxes = self._maxes
410
411 if not _maxes:
412 return
413
414 pos = bisect_left(_maxes, value)
415
416 if pos == len(_maxes):
417 return
418
419 _lists = self._lists
420 idx = bisect_left(_lists[pos], value)
421
422 if _lists[pos][idx] == value:
423 self._delete(pos, idx)
424
425
426 def remove(self, value):

Callers 3

test_discardFunction · 0.95
test_removeFunction · 0.95
wrapperFunction · 0.45

Calls 1

_deleteMethod · 0.95

Tested by 2

test_discardFunction · 0.76
test_removeFunction · 0.76