Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthiasdiener/orderedsets
An implementation of mutable and immutable ordered sets.
https://github.com/matthiasdiener/orderedsets
ordered-set python sets
Last synced: 10 days ago
JSON representation
An implementation of mutable and immutable ordered sets.
- Host: GitHub
- URL: https://github.com/matthiasdiener/orderedsets
- Owner: matthiasdiener
- License: mit
- Created: 2023-08-02T17:44:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-13T03:55:44.000Z (6 months ago)
- Last Synced: 2024-09-16T16:22:19.325Z (about 2 months ago)
- Topics: ordered-set, python, sets
- Language: Python
- Homepage: https://matthiasdiener.github.io/orderedsets/
- Size: 525 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![PyPI version](https://badge.fury.io/py/orderedsets.svg)](https://badge.fury.io/py/orderedsets)
[![Doc Status](https://img.shields.io/github/actions/workflow/status/matthiasdiener/orderedsets/doc.yaml?label=docs)](https://matthiasdiener.github.io/orderedsets)
[![License](https://img.shields.io/pypi/l/orderedsets)](https://github.com/matthiasdiener/orderedsets/blob/main/LICENSE)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/orderedsets)](https://badge.fury.io/py/orderedsets)# orderedsets
An implementation of mutable and immutable ordered sets as thin wrappers around
Python's `dict` class.
These classes are meant as drop-in replacements for Python's builtin `set` and
`frozenset` classes. Care has been taken to provide the same functionality as the Python classes,
without API additions or removals, to allow easy switching between set implementations. These classes are often
[faster than other ordered set implementations](https://matthiasdiener.github.io/orderedsets/speed.html)
(but slower than Python's builtin sets).In contrast to Python's builtin `set` and `frozenset` classes, the order of
items is kept (generally, insertion order), such that iterating over items in
the set as well as mutating operations are deterministic.This package has no external dependencies.
## Usage
Install this package with:
```
$ pip install orderedsets
```Usage example:
```python
from orderedsets import OrderedSet, FrozenOrderedSetos = OrderedSet([1, 2, 4])
os.add(0)
assert list(os) == [1, 2, 4, 0]
os.remove(0)fos = FrozenOrderedSet([1, 2, 4])
# a.add(0) # raises AttributeError: 'FrozenOrderedSet' object has no attribute 'add'
assert list(fos) == [1, 2, 4]# sets with the same elements compare equal
assert os == fos == set([1, 2, 4]) == frozenset([1, 2, 4])# only immutable sets can be hashed
assert hash(fos) == hash(frozenset([1, 2, 4]))
```Please also see the [documentation](https://matthiasdiener.github.io/orderedsets).
## References
### Other packages
- https://github.com/rindPHI/proxyorderedset/ (not 100% compatible with set)
- https://pypi.org/project/ordered-set/ (no frozen/immutable class)
- https://pypi.org/project/stableset/ (no frozen/immutable class)
- https://pypi.org/project/orderedset/ (Cython, no frozen/immutable class)
- https://pypi.org/project/Ordered-set-37/ (no frozen/immutable class)### Discussions
- https://discuss.python.org/t/add-orderedset-to-stdlib/12730
### Python implementations
- https://github.com/python/cpython/blob/main/Objects/setobject.c
- https://github.com/python/cpython/blob/main/Objects/dictobject.c