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

Method bisect_left

sortedcontainers/sortedlist.py:1166–1195  ·  view source on GitHub ↗

Return an index to insert `value` in the sorted list. If the `value` is already present, the insertion point will be before (to the left of) any existing values. Similar to the `bisect` module in the standard library. Runtime complexity: `O(log(n))` -- approximate.

(self, value)

Source from the content-addressed store, hash-verified

1164
1165
1166 def bisect_left(self, value):
1167 """Return an index to insert `value` in the sorted list.
1168
1169 If the `value` is already present, the insertion point will be before
1170 (to the left of) any existing values.
1171
1172 Similar to the `bisect` module in the standard library.
1173
1174 Runtime complexity: `O(log(n))` -- approximate.
1175
1176 >>> sl = SortedList([10, 11, 12, 13, 14])
1177 >>> sl.bisect_left(12)
1178 2
1179
1180 :param value: insertion index of value in sorted list
1181 :return: index
1182
1183 """
1184 _maxes = self._maxes
1185
1186 if not _maxes:
1187 return 0
1188
1189 pos = bisect_left(_maxes, value)
1190
1191 if pos == len(_maxes):
1192 return self._len
1193
1194 idx = bisect_left(self._lists[pos], value)
1195 return self._loc(pos, idx)
1196
1197
1198 def bisect_right(self, value):

Callers 6

test_bisect_leftFunction · 0.95
stress_bisect_leftFunction · 0.45
test_bisectFunction · 0.45
test_bisect_keyFunction · 0.45
test_bisectFunction · 0.45
stress_bisect_leftFunction · 0.45

Calls 1

_locMethod · 0.95

Tested by 6

test_bisect_leftFunction · 0.76
stress_bisect_leftFunction · 0.36
test_bisectFunction · 0.36
test_bisect_keyFunction · 0.36
test_bisectFunction · 0.36
stress_bisect_leftFunction · 0.36