A simple and efficient OrderedSet implementation
Project description
techcable.orderedset
A simple and efficient OrderedSet in pure python. Implements both MutableSet and Sequence.
Example Usage
from techcable.orderedset import OrderedSet
# prints {1, 2, 7, 3}
print(OrderedSet([1, 2, 7, 2, 3]))
# Implements all standard set methods, still preserves order
print(OrderedSet.of[1,2]) | OrderedSet([3,2,4])) # {1,2,3,4}
# OrderedSet.of(1, 2) is shorthand for OrderedSet([1, 2]),
# avoiding an extra pair of brackets
print(OrderedSet.of(1, 2)) # {1, 2}
# Implements `append` method, returning True on success
# and False if the item was a duplicate
oset = OrderedSet()
oset.append(1) # True
oset.append(2) # True
oset.append(1) # False - already in set, did nothing
oset.extend([2,3]) # True - at least one success
oset.append([2,3]) # False - all duplicates
Supports pydantic validation & serialization:
import pydantic
from techcable.orderedset import OrderedSet
model = pydantic.TypeAdapter(OrderedSet[int])
# prints OrderedSet.of(1,2,7,8)
print(repr(model.validate_python([1,2,7,8])))
assert model.dump_python(OrderedSet.of(1,2,7,8)) == [1,2,7,8]
Potential Future Features
- Implement
OrderedFrozenSet - Consider acceleration module using C/Rust/Cython
- Probably unnecessary since this has library has very little overhead compared to the builtin
set/list
- Probably unnecessary since this has library has very little overhead compared to the builtin
License
Licensed under either the Apache 2.0 License or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file techcable_orderedset-0.1.8.tar.gz.
File metadata
- Download URL: techcable_orderedset-0.1.8.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cf9316e8c069a3bafc3b09fe27966ab9744dcddb5247bfe2a88588b48a486b7
|
|
| MD5 |
20823038ecb5496d4e3d025029dec3f3
|
|
| BLAKE2b-256 |
c4d39c1d47c5c963737373dffe108108cc5f8cd368d10db4d65253000c14a386
|
File details
Details for the file techcable_orderedset-0.1.8-py3-none-any.whl.
File metadata
- Download URL: techcable_orderedset-0.1.8-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
829b74d37a54a2067c1c3560900d82199bd81114b4bed45efdb9fff5f6085f78
|
|
| MD5 |
82f1f8fd47365a2c127fe30bb5f6a3c5
|
|
| BLAKE2b-256 |
05d56cfb6a823881a56398b8a5df3eab836898b4c64a8935ce77f1ae52ecf8ab
|