Skip to main content

A simple and efficient OrderedSet implementation

Project description

techcable.orderedset

github pypi types]

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

techcable_orderedset-0.1.8.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

techcable_orderedset-0.1.8-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for techcable_orderedset-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7cf9316e8c069a3bafc3b09fe27966ab9744dcddb5247bfe2a88588b48a486b7
MD5 20823038ecb5496d4e3d025029dec3f3
BLAKE2b-256 c4d39c1d47c5c963737373dffe108108cc5f8cd368d10db4d65253000c14a386

See more details on using hashes here.

File details

Details for the file techcable_orderedset-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for techcable_orderedset-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 829b74d37a54a2067c1c3560900d82199bd81114b4bed45efdb9fff5f6085f78
MD5 82f1f8fd47365a2c127fe30bb5f6a3c5
BLAKE2b-256 05d56cfb6a823881a56398b8a5df3eab836898b4c64a8935ce77f1ae52ecf8ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page