Set
Bases: PyoSet[T]
flowchart TD
pyochain._set.Set[Set]
pyochain.abc._set.PyoSet[PyoSet]
pyochain.abc._collection.PyoCollection[PyoCollection]
pyochain.abc._iterable.PyoIterable[PyoIterable]
pyochain.rs.Pipeable[Pipeable]
pyochain.rs.Into[Into]
pyochain.rs.Inspect[Inspect]
pyochain.rs.Checkable[Checkable]
pyochain.abc._collection.PyoContainer[PyoContainer]
pyochain.abc._collection.PyoSized[PyoSized]
pyochain.abc._set.PyoSet --> pyochain._set.Set
pyochain.abc._collection.PyoCollection --> pyochain.abc._set.PyoSet
pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
pyochain.rs.Pipeable --> pyochain.abc._iterable.PyoIterable
pyochain.rs.Into --> pyochain.rs.Pipeable
pyochain.rs.Inspect --> pyochain.rs.Pipeable
pyochain.rs.Checkable --> pyochain.abc._iterable.PyoIterable
pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
click pyochain._set.Set href "" "pyochain._set.Set"
click pyochain.abc._set.PyoSet href "" "pyochain.abc._set.PyoSet"
click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
click pyochain.rs.Pipeable href "" "pyochain.rs.Pipeable"
click pyochain.rs.Into href "" "pyochain.rs.Into"
click pyochain.rs.Inspect href "" "pyochain.rs.Inspect"
click pyochain.rs.Checkable href "" "pyochain.rs.Checkable"
click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
Set represent an in- memory unordered collection of unique elements.
Implements the collections::abc::Collection Protocol, so it can be used as a standard immutable collection.
The underlying data structure is a frozenset.
Tip
Set(frozenset)is a no-copy operation since Python optimizes this under the hood.- If you have an existing
set, consider usingSetMut::from_refto avoid unnecessary copying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
Any |
required |
Example
>>> from pyochain import Set
>>> Set(())
Set()
>>> s = Set((1, 2, 2, 3))
>>> s
Set(1, 2, 3)
>>> s_2 = Set(s.inner)
>>> # No copy is made when creating s_2 from s.inner, they reference the same underlying frozenset.
>>> is_no_copy = (
... s.inner is s_2.inner
... and s.inner is s.inner
... and s_2.inner is s.inner
... and frozenset(s.inner) is s.inner
... )
>>> is_no_copy
True
>>> # However, creating a new Set from s (not using .inner) will be a copy operation.
>>> Set(s).inner is s.inner
False
Source code in src/pyochain/_set.py
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
inner
property
Get the underlying frozenset data structure.
Useful when interoperating with functions that require a standard Python frozenset.
Returns:
| Type | Description |
|---|---|
frozenset[T]
|
frozenset[T]: The underlying frozenset. |