Metadata-Version: 2.1
Name: orderedsets
Version: 2023.3
Summary: An implementation of mutable and immutable ordered sets.
Author-email: Matthias Diener <matthias.diener@gmail.com>, Andreas Kloeckner <inform@tiker.net>
License: MIT License
        
        Copyright (c) 2023 University of Illinois Board of Trustees
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/matthiasdiener/orderedsets/
Project-URL: Bug Tracker, https://github.com/matthiasdiener/orderedsets/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: importlib-metadata ; python_version < "3.8"

[![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)
![PyPI - Downloads](https://img.shields.io/pypi/dm/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.

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, FrozenOrderedSet

os = 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
