Skip to content

SortedKeySet

Bases: BaseSortedSet[T]


              flowchart TD
              pyochain.collections._sorted._keyset.SortedKeySet[SortedKeySet]
              pyochain.collections._sorted._set.BaseSortedSet[BaseSortedSet]
              pyochain.abc._mutable_set.PyoMutableSet[PyoMutableSet]
              pyochain.abc._set.PyoSet[PyoSet]
              pyochain.abc._sequences.PyoSequence[PyoSequence]
              pyochain.abc._sequences.PyoReversible[PyoReversible]
              pyochain.abc._collection.PyoCollection[PyoCollection]
              pyochain.abc._iterable.PyoIterable[PyoIterable]
              pyochain.abc._collection.PyoContainer[PyoContainer]
              pyochain.abc._collection.PyoSized[PyoSized]
              pyochain.abc._mixins.Checkable[Checkable]
              pyochain.abc._mixins.Fluent[Fluent]
              pyochain.abc._mixins.Pipe[Pipe]
              pyochain.abc._mixins.Tap[Tap]
              pyochain.collections._sorted._core.BaseSortedListSet[BaseSortedListSet]
              pyochain.collections._sorted._core.SortedCollection[SortedCollection]

                              pyochain.collections._sorted._set.BaseSortedSet --> pyochain.collections._sorted._keyset.SortedKeySet
                                pyochain.abc._mutable_set.PyoMutableSet --> pyochain.collections._sorted._set.BaseSortedSet
                                pyochain.abc._set.PyoSet --> pyochain.abc._mutable_set.PyoMutableSet
                                pyochain.abc._collection.PyoCollection --> pyochain.abc._set.PyoSet
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                


                pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
                

                pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
                




                pyochain.abc._sequences.PyoSequence --> pyochain.collections._sorted._set.BaseSortedSet
                                pyochain.abc._sequences.PyoReversible --> pyochain.abc._sequences.PyoSequence
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._sequences.PyoReversible
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                



                pyochain.abc._collection.PyoCollection --> pyochain.abc._sequences.PyoSequence
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                


                pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
                

                pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
                



                pyochain.collections._sorted._core.BaseSortedListSet --> pyochain.collections._sorted._set.BaseSortedSet
                                pyochain.collections._sorted._core.SortedCollection --> pyochain.collections._sorted._core.BaseSortedListSet
                




              click pyochain.collections._sorted._keyset.SortedKeySet href "" "pyochain.collections._sorted._keyset.SortedKeySet"
              click pyochain.collections._sorted._set.BaseSortedSet href "" "pyochain.collections._sorted._set.BaseSortedSet"
              click pyochain.abc._mutable_set.PyoMutableSet href "" "pyochain.abc._mutable_set.PyoMutableSet"
              click pyochain.abc._set.PyoSet href "" "pyochain.abc._set.PyoSet"
              click pyochain.abc._sequences.PyoSequence href "" "pyochain.abc._sequences.PyoSequence"
              click pyochain.abc._sequences.PyoReversible href "" "pyochain.abc._sequences.PyoReversible"
              click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
              click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
              click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
              click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
              click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
              click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
              click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
              click pyochain.collections._sorted._core.BaseSortedListSet href "" "pyochain.collections._sorted._core.BaseSortedListSet"
              click pyochain.collections._sorted._core.SortedCollection href "" "pyochain.collections._sorted._core.SortedCollection"
            
Source code in pyochain/collections/_sorted/_keyset.pyi
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@final
# pyrefly: ignore [bad-specialization]
class SortedKeySet[T, OT: SupportsHashableAndRichComparison](BaseSortedSet[T]):  # pyright: ignore[reportInvalidTypeArguments]
    def __new__(
        cls, iterable: Iterable[T] | None = None, key: SetKeyFunc[T, OT] | None = None
    ) -> Self:
        """Initialize sorted set instance based on a key function.

        Optional `iterable` argument provides an initial iterable of values to initialize the sorted key set.

        The `key` argument defines a `Callable` that, like the `key` argument to Python's `sorted` function, extracts a comparison key from each value.

        The default, `None`, compares values directly.

        Runtime complexity: `O(n*log(n))`

        Args:
            iterable (Iterable[T] | None): initial values (optional)
            key (SetKeyFunc[T, OT] | None): function used to extract comparison key

        Returns:
            Self: new sorted-key set

        Examples:
            ```python
            from pyochain.collections import SortedKeySet
            from operator import neg

            ss = SortedKeySet([3, 1, 2, 5, 4], neg)
            assert (
                repr(ss) == "SortedKeySet([5, 4, 3, 2, 1], key=<built-in function neg>)"
            )
            ```

        """

    @override
    # pyrefly: ignore [bad-override]
    def __reduce__(  # pyright: ignore[reportIncompatibleMethodOverride]
        self,
    ) -> tuple[type[Self], tuple[AbstractSet[T], Callable[[T], Any]]]: ...
    @property
    def key(self) -> SetKeyFunc[T, OT]:
        """Function used to extract comparison key from values.

        Sorted set compares values directly when the key function is none.

        """

    def irange_key(
        self,
        min_key: OT | None = None,
        max_key: OT | None = None,
        inclusive: tuple[bool, bool] = (True, True),
        *,
        reverse: bool = False,
    ) -> PyoIterator[T]: ...
    def bisect_key_left(self, key: OT) -> int: ...
    def bisect_key_right(self, key: OT) -> int: ...
    @override
    def union(self, *iterables: Iterable[T]) -> Self: ...

key property

Function used to extract comparison key from values.

Sorted set compares values directly when the key function is none.

__new__(iterable=None, key=None)

Initialize sorted set instance based on a key function.

Optional iterable argument provides an initial iterable of values to initialize the sorted key set.

The key argument defines a Callable that, like the key argument to Python's sorted function, extracts a comparison key from each value.

The default, None, compares values directly.

Runtime complexity: O(n*log(n))

Parameters:

Name Type Description Default
iterable Iterable[T] | None

initial values (optional)

None
key SetKeyFunc[T, OT] | None

function used to extract comparison key

None

Returns:

Name Type Description
Self Self

new sorted-key set

Examples:

from pyochain.collections import SortedKeySet
from operator import neg

ss = SortedKeySet([3, 1, 2, 5, 4], neg)
assert (
    repr(ss) == "SortedKeySet([5, 4, 3, 2, 1], key=<built-in function neg>)"
)
Source code in pyochain/collections/_sorted/_keyset.pyi
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def __new__(
    cls, iterable: Iterable[T] | None = None, key: SetKeyFunc[T, OT] | None = None
) -> Self:
    """Initialize sorted set instance based on a key function.

    Optional `iterable` argument provides an initial iterable of values to initialize the sorted key set.

    The `key` argument defines a `Callable` that, like the `key` argument to Python's `sorted` function, extracts a comparison key from each value.

    The default, `None`, compares values directly.

    Runtime complexity: `O(n*log(n))`

    Args:
        iterable (Iterable[T] | None): initial values (optional)
        key (SetKeyFunc[T, OT] | None): function used to extract comparison key

    Returns:
        Self: new sorted-key set

    Examples:
        ```python
        from pyochain.collections import SortedKeySet
        from operator import neg

        ss = SortedKeySet([3, 1, 2, 5, 4], neg)
        assert (
            repr(ss) == "SortedKeySet([5, 4, 3, 2, 1], key=<built-in function neg>)"
        )
        ```

    """