MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / bisect_right

Method bisect_right

sortedcontainers/sortedlist.py:1198–1227  ·  view source on GitHub ↗

Return an index to insert `value` in the sorted list. Similar to `bisect_left`, but if `value` is already present, the insertion point will be after (to the right of) any existing values. Similar to the `bisect` module in the standard library. Runtime complexity: `

(self, value)

Source from the content-addressed store, hash-verified

1196
1197
1198 def bisect_right(self, value):
1199 """Return an index to insert `value` in the sorted list.
1200
1201 Similar to `bisect_left`, but if `value` is already present, the
1202 insertion point will be after (to the right of) any existing values.
1203
1204 Similar to the `bisect` module in the standard library.
1205
1206 Runtime complexity: `O(log(n))` -- approximate.
1207
1208 >>> sl = SortedList([10, 11, 12, 13, 14])
1209 >>> sl.bisect_right(12)
1210 3
1211
1212 :param value: insertion index of value in sorted list
1213 :return: index
1214
1215 """
1216 _maxes = self._maxes
1217
1218 if not _maxes:
1219 return 0
1220
1221 pos = bisect_right(_maxes, value)
1222
1223 if pos == len(_maxes):
1224 return self._len
1225
1226 idx = bisect_right(self._lists[pos], value)
1227 return self._loc(pos, idx)
1228
1229 bisect = bisect_right
1230 _bisect_right = bisect_right

Callers 6

test_bisect_rightFunction · 0.95
stress_bisect_rightFunction · 0.45
test_bisectFunction · 0.45
test_bisect_keyFunction · 0.45
test_bisectFunction · 0.45
stress_bisect_rightFunction · 0.45

Calls 1

_locMethod · 0.95

Tested by 6

test_bisect_rightFunction · 0.76
stress_bisect_rightFunction · 0.36
test_bisectFunction · 0.36
test_bisect_keyFunction · 0.36
test_bisectFunction · 0.36
stress_bisect_rightFunction · 0.36