omnipy.util.setdeque
Ordered unique queue utilities.
This module provides SetDeque, a deque-backed data structure that preserves
insertion order like collections.deque while enforcing set-like uniqueness.
It is useful for work queues, caches, and registration lists where membership
checks must be fast and duplicates should be ignored instead of accumulated.
| CLASS | DESCRIPTION |
|---|---|
SetDeque |
Deque variant that keeps each element at most once. |
SetDeque
Bases: deque, Generic[_ObjT]
flowchart BT
omnipy.util.setdeque.SetDeque[SetDeque]
click omnipy.util.setdeque.SetDeque href "" "omnipy.util.setdeque.SetDeque"
Deque variant that keeps each element at most once.
SetDeque combines the ordered, append/pop-friendly behavior of
collections.deque with an internal set for O(1) membership tests.
Duplicate insertions are ignored, existing order is preserved, and explicit
removals keep the deque and set views synchronized.
| PARAMETER | DESCRIPTION |
|---|---|
iterable
|
Initial values. Later duplicates are discarded while keeping the first occurrence.
TYPE:
|
maxlen
|
Optional deque length limit passed through to
TYPE:
|
Notes
When maxlen causes deque to evict elements during appends, this
implementation does not proactively remove evicted values from the backing
set. Use this type primarily without maxlen unless that edge case is
acceptable for the calling code.
- Reference Code reference omnipy
-
Reference
Code reference
omnipy
util
memoRefCountMemoDictrecursively_remove_deleted_objs
| METHOD | DESCRIPTION |
|---|---|
__init__ |
|
append |
Append a new element to the right side. |
appendleft |
Append a new element to the left side. |
clear |
Remove all elements and reset membership bookkeeping. |
count |
Return whether an element is present. |
extend |
Append unique elements from an iterable to the right side. |
extendleft |
Append unique elements from an iterable to the left side. |
insert |
Insert a new element at a position. |
pop |
Remove and return the rightmost element. |
popleft |
Remove and return the leftmost element. |
remove |
Remove an element from the deque and membership set. |
Source code in src/omnipy/util/setdeque.py
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__init__
append
Append a new element to the right side.
| PARAMETER | DESCRIPTION |
|---|---|
el
|
Element to append when it is not already present.
TYPE:
|
appendleft
Append a new element to the left side.
| PARAMETER | DESCRIPTION |
|---|---|
el
|
Element to append when it is not already present.
TYPE:
|
clear
Remove all elements and reset membership bookkeeping.
This keeps deque contents and the internal uniqueness set synchronized.
count
Return whether an element is present.
| PARAMETER | DESCRIPTION |
|---|---|
__x
|
Element to check for membership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
|
Source code in src/omnipy/util/setdeque.py
extend
Append unique elements from an iterable to the right side.
| PARAMETER | DESCRIPTION |
|---|---|
el_iter
|
Source iterable. Duplicate values are ignored.
TYPE:
|
extendleft
Append unique elements from an iterable to the left side.
| PARAMETER | DESCRIPTION |
|---|---|
el_iter
|
Source iterable. Duplicate values are ignored.
TYPE:
|
insert
Insert a new element at a position.
| PARAMETER | DESCRIPTION |
|---|---|
__i
|
Index at which to insert.
TYPE:
|
__x
|
Element to insert when it is not already present.
TYPE:
|
pop
Remove and return the rightmost element.
| RETURNS | DESCRIPTION |
|---|---|
_ObjT
|
The removed element. |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If the deque is empty. |
popleft
Remove and return the leftmost element.
| RETURNS | DESCRIPTION |
|---|---|
_ObjT
|
The removed element. |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If the deque is empty. |
remove
Remove an element from the deque and membership set.
| PARAMETER | DESCRIPTION |
|---|---|
__value
|
Element to remove.
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the element is not present. |