sortedlist.pyi 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, iterable: Optional[Iterable[_T]] = ..., key: Optional[_Key[_T]] = ...,
  30. ): ...
  31. # NB: currently mypy does not honour return type, see mypy #3307
  32. @overload
  33. def __new__(cls: Type[_SL], iterable: None, key: None) -> _SL: ...
  34. @overload
  35. def __new__(cls: Type[_SL], iterable: None, key: _Key[_T]) -> SortedKeyList[_T]: ...
  36. @overload
  37. def __new__(cls: Type[_SL], iterable: Iterable[_T], key: None) -> _SL: ...
  38. @overload
  39. def __new__(cls, iterable: Iterable[_T], key: _Key[_T]) -> SortedKeyList[_T]: ...
  40. @property
  41. def key(self) -> Optional[Callable[[_T], Any]]: ...
  42. def _reset(self, load: int) -> None: ...
  43. def clear(self) -> None: ...
  44. def _clear(self) -> None: ...
  45. def add(self, value: _T) -> None: ...
  46. def _expand(self, pos: int) -> None: ...
  47. def update(self, iterable: Iterable[_T]) -> None: ...
  48. def _update(self, iterable: Iterable[_T]) -> None: ...
  49. def discard(self, value: _T) -> None: ...
  50. def remove(self, value: _T) -> None: ...
  51. def _delete(self, pos: int, idx: int) -> None: ...
  52. def _loc(self, pos: int, idx: int) -> int: ...
  53. def _pos(self, idx: int) -> int: ...
  54. def _build_index(self) -> None: ...
  55. def __contains__(self, value: Any) -> bool: ...
  56. def __delitem__(self, index: Union[int, slice]) -> None: ...
  57. @overload
  58. def __getitem__(self, index: int) -> _T: ...
  59. @overload
  60. def __getitem__(self, index: slice) -> List[_T]: ...
  61. @overload
  62. def _getitem(self, index: int) -> _T: ...
  63. @overload
  64. def _getitem(self, index: slice) -> List[_T]: ...
  65. @overload
  66. def __setitem__(self, index: int, value: _T) -> None: ...
  67. @overload
  68. def __setitem__(self, index: slice, value: Iterable[_T]) -> None: ...
  69. def __iter__(self) -> Iterator[_T]: ...
  70. def __reversed__(self) -> Iterator[_T]: ...
  71. def __len__(self) -> int: ...
  72. def reverse(self) -> None: ...
  73. def islice(
  74. self, start: Optional[int] = ..., stop: Optional[int] = ..., reverse=bool,
  75. ) -> Iterator[_T]: ...
  76. def _islice(
  77. self, min_pos: int, min_idx: int, max_pos: int, max_idx: int, reverse: bool,
  78. ) -> Iterator[_T]: ...
  79. def irange(
  80. self,
  81. minimum: Optional[int] = ...,
  82. maximum: Optional[int] = ...,
  83. inclusive: Tuple[bool, bool] = ...,
  84. reverse: bool = ...,
  85. ) -> Iterator[_T]: ...
  86. def bisect_left(self, value: _T) -> int: ...
  87. def bisect_right(self, value: _T) -> int: ...
  88. def bisect(self, value: _T) -> int: ...
  89. def _bisect_right(self, value: _T) -> int: ...
  90. def count(self, value: _T) -> int: ...
  91. def copy(self: _SL) -> _SL: ...
  92. def __copy__(self: _SL) -> _SL: ...
  93. def append(self, value: _T) -> None: ...
  94. def extend(self, values: Iterable[_T]) -> None: ...
  95. def insert(self, index: int, value: _T) -> None: ...
  96. def pop(self, index: int = ...) -> _T: ...
  97. def index(
  98. self, value: _T, start: Optional[int] = ..., stop: Optional[int] = ...
  99. ) -> int: ...
  100. def __add__(self: _SL, other: Iterable[_T]) -> _SL: ...
  101. def __radd__(self: _SL, other: Iterable[_T]) -> _SL: ...
  102. def __iadd__(self: _SL, other: Iterable[_T]) -> _SL: ...
  103. def __mul__(self: _SL, num: int) -> _SL: ...
  104. def __rmul__(self: _SL, num: int) -> _SL: ...
  105. def __imul__(self: _SL, num: int) -> _SL: ...
  106. def __eq__(self, other: Any) -> bool: ...
  107. def __ne__(self, other: Any) -> bool: ...
  108. def __lt__(self, other: Sequence[_T]) -> bool: ...
  109. def __gt__(self, other: Sequence[_T]) -> bool: ...
  110. def __le__(self, other: Sequence[_T]) -> bool: ...
  111. def __ge__(self, other: Sequence[_T]) -> bool: ...
  112. def __repr__(self) -> str: ...
  113. def _check(self) -> None: ...
  114. class SortedKeyList(SortedList[_T]):
  115. def __init__(
  116. self, iterable: Optional[Iterable[_T]] = ..., key: _Key[_T] = ...
  117. ) -> None: ...
  118. def __new__(
  119. cls, iterable: Optional[Iterable[_T]] = ..., key: _Key[_T] = ...
  120. ) -> SortedKeyList[_T]: ...
  121. @property
  122. def key(self) -> Callable[[_T], Any]: ...
  123. def clear(self) -> None: ...
  124. def _clear(self) -> None: ...
  125. def add(self, value: _T) -> None: ...
  126. def _expand(self, pos: int) -> None: ...
  127. def update(self, iterable: Iterable[_T]) -> None: ...
  128. def _update(self, iterable: Iterable[_T]) -> None: ...
  129. # NB: Must be T to be safely passed to self.func, yet base class imposes Any
  130. def __contains__(self, value: _T) -> bool: ... # type: ignore
  131. def discard(self, value: _T) -> None: ...
  132. def remove(self, value: _T) -> None: ...
  133. def _delete(self, pos: int, idx: int) -> None: ...
  134. def irange(
  135. self,
  136. minimum: Optional[int] = ...,
  137. maximum: Optional[int] = ...,
  138. inclusive: Tuple[bool, bool] = ...,
  139. reverse: bool = ...,
  140. ): ...
  141. def irange_key(
  142. self,
  143. min_key: Optional[Any] = ...,
  144. max_key: Optional[Any] = ...,
  145. inclusive: Tuple[bool, bool] = ...,
  146. reserve: bool = ...,
  147. ): ...
  148. def bisect_left(self, value: _T) -> int: ...
  149. def bisect_right(self, value: _T) -> int: ...
  150. def bisect(self, value: _T) -> int: ...
  151. def bisect_key_left(self, key: Any) -> int: ...
  152. def _bisect_key_left(self, key: Any) -> int: ...
  153. def bisect_key_right(self, key: Any) -> int: ...
  154. def _bisect_key_right(self, key: Any) -> int: ...
  155. def bisect_key(self, key: Any) -> int: ...
  156. def count(self, value: _T) -> int: ...
  157. def copy(self: _SKL) -> _SKL: ...
  158. def __copy__(self: _SKL) -> _SKL: ...
  159. def index(
  160. self, value: _T, start: Optional[int] = ..., stop: Optional[int] = ...
  161. ) -> int: ...
  162. def __add__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  163. def __radd__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  164. def __iadd__(self: _SKL, other: Iterable[_T]) -> _SKL: ...
  165. def __mul__(self: _SKL, num: int) -> _SKL: ...
  166. def __rmul__(self: _SKL, num: int) -> _SKL: ...
  167. def __imul__(self: _SKL, num: int) -> _SKL: ...
  168. def __repr__(self) -> str: ...
  169. def _check(self) -> None: ...
  170. SortedListWithKey = SortedKeyList