MultiBidict
class¶
Bases: Generic[_KT, _VT]
A generic multikeyed, multivalued bidirectional dictionary.
Notes:
-
This class provides a flexible mapping structure that enables efficient lookups, updates, and deletions of keys and their corresponding values.
-
Although this class uses a bidirectional mapping structure, its memory footprint remains minimal due to the use of references between keys and values instead of duplication, which limits the impact to the additional dictionary and set data structures.
-
Most methods in this class operate with an average time complexity of O(1), ensuring high efficiency. However, the performance of removal operations may vary depending on the relationships between keys and values.
-
This class is not inherently designed for concurrent access; therefore, thread safety considerations should be taken into account when using it in multithreaded environments.
Source code in pyventus/core/collections/multi_bidict.py
12 13 14 15 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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
Attributes¶
is_empty
property
¶
Determine whether the dictionary is empty.
RETURNS | DESCRIPTION |
---|---|
bool
|
|
keys
property
¶
Retrieve all keys from the dictionary.
RETURNS | DESCRIPTION |
---|---|
set[_KT]
|
A set of all keys in the dictionary. |
values
property
¶
Retrieve all values from the dictionary.
RETURNS | DESCRIPTION |
---|---|
set[_VT]
|
A set of all values in the dictionary. |
key_count
property
¶
Retrieve the number of unique keys in the dictionary.
RETURNS | DESCRIPTION |
---|---|
int
|
The total count of keys in the dictionary. |
value_count
property
¶
Retrieve the number of unique values in the dictionary.
RETURNS | DESCRIPTION |
---|---|
int
|
The total count of values in the dictionary. |
Functions¶
__init__
¶
Initialize an instance of MultiBidict
.
This constructor sets up two dictionaries: one for storing the forward mapping of keys to values and another for the inverse mapping of values to keys. Both dictionaries are initialized as empty.
Source code in pyventus/core/collections/multi_bidict.py
get_keys_from_values
¶
Retrieve a set of keys associated with the specified values.
PARAMETER | DESCRIPTION |
---|---|
values
|
A set of values for which to retrieve the associated keys.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[_KT]
|
A set of keys associated with the given values. Unregistered values are ignored. |
Source code in pyventus/core/collections/multi_bidict.py
get_values_from_keys
¶
Retrieve a set of values associated with the specified keys.
PARAMETER | DESCRIPTION |
---|---|
keys
|
A set of keys for which to retrieve the associated values.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[_VT]
|
A set of values associated with the given keys. Unregistered keys are ignored. |
Source code in pyventus/core/collections/multi_bidict.py
get_key_count_from_value
¶
Retrieve the number of keys associated with the specified value.
PARAMETER | DESCRIPTION |
---|---|
value
|
The value for which to count the associated keys.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The count of keys associated with the specified value, or 0 if the value is not found. |
Source code in pyventus/core/collections/multi_bidict.py
get_value_count_from_key
¶
Return the number of values associated with a given key.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for which to count the associated values.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The count of values associated with the specified key, or 0 if the key is not found. |
Source code in pyventus/core/collections/multi_bidict.py
contains_key
¶
Determine if the specified key is present in the dictionary.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to be checked.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
Source code in pyventus/core/collections/multi_bidict.py
contains_value
¶
Determine if the specified value is present in the dictionary.
PARAMETER | DESCRIPTION |
---|---|
value
|
The value to be checked.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
Source code in pyventus/core/collections/multi_bidict.py
are_associated
¶
Determine whether the given key is associated with the specified value.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for which the association is being checked.
TYPE:
|
value
|
The value for which the association is being checked.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
|
Source code in pyventus/core/collections/multi_bidict.py
insert
¶
Insert the given value with the specified key into the dictionary.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to which the value will be associated.
TYPE:
|
value
|
The value to be inserted for the key.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in pyventus/core/collections/multi_bidict.py
remove
¶
Remove the specified value from the given key.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key from which the value will be removed.
TYPE:
|
value
|
The value to be removed from the key.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the key or value is not registered or associated. |
Source code in pyventus/core/collections/multi_bidict.py
remove_key
¶
Remove the specified key from the dictionary.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to be removed from the dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the key is not registered. |
Source code in pyventus/core/collections/multi_bidict.py
remove_value
¶
Remove the specified value from the dictionary.
PARAMETER | DESCRIPTION |
---|---|
value
|
The value to be removed from the dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the value is not registered. |
Source code in pyventus/core/collections/multi_bidict.py
pop_key
¶
Remove the specified key from the dictionary and returns the associated values.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to be removed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[_VT]
|
A set of values associated with the removed key. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the key is not found in the dictionary. |
Source code in pyventus/core/collections/multi_bidict.py
pop_value
¶
Remove the specified value from the dictionary and returns the associated keys.
PARAMETER | DESCRIPTION |
---|---|
value
|
The value to be removed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[_KT]
|
A set of keys associated with the removed value. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the value is not found in the dictionary. |
Source code in pyventus/core/collections/multi_bidict.py
clear
¶
Clear the dictionary by removing all keys and values.
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
to_dict
¶
Retrieve a shallow copy of the dictionary.
RETURNS | DESCRIPTION |
---|---|
dict[_KT, set[_VT]]
|
A shallow copy of the main dictionary, where each key is mapped to a set of its associated values. |