sortedlist.pyi 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # stub for SortedList. This is an exact copy of
  2. # https://github.com/grantjenks/python-sortedcontainers/blob/a419ffbd2b1c935b09f11f0971696e537fd0c510/sortedcontainers/sortedlist.pyi
  3. # (from https://github.com/grantjenks/python-sortedcontainers/pull/107)
  4. from typing import (
  5. Any,
  6. Callable,
  7. Generic,
  8. Iterable,
  9. Iterator,
  10. List,
  11. MutableSequence,
  12. Optional,
  13. Sequence,
  14. Tuple,
  15. Type,
  16. TypeVar,
  17. Union,
  18. overload,
  19. )
  20. _T = TypeVar("_T")
  21. _SL = TypeVar("_SL", bound=SortedList)
  22. _SKL = TypeVar("_SKL", bound=SortedKeyList)
  23. _Key = Callable[[_T], Any]
  24. _Repr = Callable[[], str]
  25. def recursive_repr(fillvalue: str = ...) -> Callable[[_Repr], _Repr]: ...
  26. class SortedList(MutableSequence[_T]):
  27. DEFAULT_LOAD_FACTOR: int = ...
  28. def __init__(
  29. self,
  30. iterable: Optional[Iterable[_T]] = ...,
  31. key: Optional[_Key[_T]] = ...,
  32. ): ...
  33. # NB: currently mypy does not honour return type, see mypy #3307
  34. @overload
  35. def __new__(cls: Type[_SL], iterable: None, key: None) -> _SL: ...
  36. @overload
  37. def __new__(cls: Type[_SL], iterable: None, key: _Key[_T]) -> SortedKeyList[_T]: ...
  38. @overload
  39. def __new__(cls: Type[_SL], iterable: Iterable[_T], key: None) -> _SL: ...
  40. @overload
  41. def __new__(cls, iterable: Iterable[_T], key: _Key[_T]) -> SortedKeyList[_T]: ...
  42. @property
  43. def key(self) -> Optional[Callable[[_T], Any]]: ...
  44. def _reset(self, load: int) -> None: ...
  45. def clear(self) -> None: ...
  46. def _clear(self) -> None: ...
  47. def add(self, value: _T) -> None: ...
  48. def _expand(self, pos: int) -> None: ...
  49. def update(self, iterable: Iterable[_T]) -> None: ...
  50. def _update(self, iterable: Iterable[_T]) -> None: ...
  51. def discard(self, value: _T) -> None: ...
  52. def remove(self, value: _T) -> None: ...
  53. def _delete(self, pos: int, idx: int) -> None: ...
  54. def _loc(self, pos: int, idx: int) -> int: ...
  55. def _pos(self, idx: int) -> int: ...
  56. def _build_index(self) -> None: ...
  57. def __contains__(self, value: Any) -> bool: ...
  58. def __delitem__(self, index: Union[int, slice]) -> None: ...
  59. @overload
  60. def __getitem__(self, index: int) -> _T: ...
  61. @overload
  62. def __getitem__(self, index: slice) -> List[_T]: ...
  63. @overload
  64. def _getitem(self, index: int) -> _T: ...
  65. @overload
  66. def _getitem(self, index: slice) -> List[_T]: ...
  67. @overload
  68. def __setitem__(self, index: int, value: _T) -> None: ...
  69. @overload
  70. def __setitem__(self, index: slice, value: Iterable[_T]) -> None: ...
  71. def __iter__(self) -> Iterator[_T]: ...
  72. def __reversed__(self) -> Iterator[_T]: ...
  73. def __len__(self) -> int: ...
  74. def reverse(self) -> None: ...
  75. def islice(
  76. self,
  77. start: Optional[int] = ...,
  78. stop: Optional[int] = ...,
  79. reverse=bool,
  80. ) -> Iterator[_T]: ...
  81. def _islice(
  82. self,
  83. min_pos: int,
  84. min_idx: int,
  85. max_pos: int,
  86. max_idx: int,
  87. reverse: bool,
  88. ) -> Iterator[_T]: ...
  89. def irange(
  90. self,
  91. minimum: Optional[int] = ...,
  92. maximum: Optional[int] = ...,
  93. inclusive: Tuple[bool, bool] = ...,
  94. reverse: bool = ...,
  95. ) -> Iterator[_T]: ...
  96. def bisect_left(self, value: _T) -> int: ...
  97. def bisect_right(self, value: _T) -> int: ...
  98. def bisect(self, value: _T) -> int: ...
  99. def _bisect_right(self, value: _T) -> int: ...
  100. def count(self, value: _T) -> int: ...
  101. def copy(self: _SL) -> _SL: ...
  102. def __copy__(self: _SL) -> _SL: ...
  103. def append(self, value: _T) -> None: ...
  104. def extend(self, values: Iterable[_T]) -> None: ...
  105. def insert(self, index: int, value: _T) -> None: ...
  106. def pop(self, index: int = ...) -> _T: ...
  107. def index(
  108. self, value: _T, start: Optional[int] = ..., stop: Optional[int] = ...
  109. ) -> int: ...
  110. def __add__(self: _SL, other: Iterable[_T]) -> _SL: ...
  111. def __radd__(self: _SL, other: Iterable[_T]) -> _SL: ...
  112. def __iadd__(self: _SL, other: Iterable[_T]) -> _SL: ...
  113. def __mul__(self: _SL, num: int) -> _SL: ...
  114. def __rmul__(self: _SL, num: int) -> _SL: ...
  115. def __imul__(self: _SL, num: int) -> _SL: ...
  116. def __eq__(self, other: Any) -> bool: ...
  117. def __ne__(self, other: Any) -> bool: ...
  118. def __lt__(self, other: Sequence[_T]) -> bool: ...
  119. def __gt__(self, other: Sequence[_T]) -> bool: ...
  120. def __le__(self, other: Sequence[_T]) -> bool: ...
  121. def __ge__(self, other: Sequence[_T]) -> bool: ...
  122. def __repr__(self) -> str: ...
  123. def _check(self) -> None: ...
  124. class SortedKeyList(SortedList[_T]):
  125. def __init__(
  126. self, iterable: Optional[Iterable[_T]] = ..., key: _Key[_T] = ...
  127. ) -> None: ...
  128. def __new__(
  129. cls, iterable: Optional[Iterable[_T]] = ..., key: _Key[_T] = ...
  130. ) -> SortedKeyList[_T]: ...
  131. @property
  132. def key(self) -> Callable[[_T], Any]: ...
  133. def clear(self) -> None: ...
  134. def _clear(self) -> None: ...
  135. def add(self, value: _T) -> None: ...
  136. def _expand(self, pos: int) -> None: ...
  137. def update(self, iterable: Iterable[_T]) -> None: ...
  138. def _update(self, iterable: Iterable[_T]) -> None: ...
  139. # NB: Must be T to be safely passed to self.func, yet base class imposes Any
  140. def __contains__(self, value: _T) -> bool: ... # type: ignore
  141. def discard(self, value: _T) -> None: ...
  142. def remove(self, value: _T) -> None: ...
  143. def _delete(self, pos: int, idx: int) -> None: ...
  144. def irange(
  145. self,
  146. minimum: Optional[int] = ...,
  147. maximum: Optional[int] = ...,
  148. inclusive: Tuple[bool, bool] = ...,
  149. reverse: bool = ...,
  150. ): ...
  151. def irange_key(
  152. self,
  153. min_key: Optional[Any] = ...,
  154. max_key: Optional[Any] = ...,
  155. inclusive: Tuple[bool, bool] = ...,
  156. reserve: bool = ...,
  157. ): ...
  158. def bisect_left(self, value: _T) -> int: ...
  159. def bisect_right(self, value: _T) -> int: ...
  160. def bisect(self, value: _T) -> int: ...
  161. def bisect_key_left(self, key: Any) -> int: ...
  162. def _bisect_key_left(self, key: Any) -> int: ...
  163. def bisect_key_right(self, key: Any) -> int: ...
  164. def _bisect_key_right(self, key: Any) -> int: ...
  165. def bisect_key(self, key: Any) -> int: ...
  166. def count(self, value: _T) -> int: ...
  167. def copy(self: _SKL) -> _SKL: ...
  168. def __copy__(self: _SKL) -> _SKL: ...
  169. def index(
  170. self, value: _T, start: Optional[int] = ..., stop: Optional[int] = ...
  171. ) -> int: ...
  172. def __add__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  173. def __radd__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  174. def __iadd__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  175. def __mul__(self: _SKL, num: int) -> _SKL: ...
  176. def __rmul__(self: _SKL, num: int) -> _SKL: ...
  177. def __imul__(self: _SKL, num: int) -> _SKL: ...
  178. def __repr__(self) -> str: ...
  179. def _check(self) -> None: ...
  180. SortedListWithKey = SortedKeyList