A MutableSet that remembers its order, so that every entry has an index
Python
Latest commit 2e5653a May 24, 2016 Rob Speer Make .discard run efficiently. Fixes #19.
Permalink
Failed to load latest commit information.
.gitignore Use tox to run tests on multiple Python VMs Nov 5, 2014
MIT-LICENSE
README version 2.0 because we made an API change to tuples Dec 15, 2015
ordered_set.py Make .discard run efficiently. Fixes #19. May 24, 2016
setup.py bump version to 2.0.1 to fix inconsistent version Mar 29, 2016
test.py update tests for tuples Dec 15, 2015
tox.ini tested on 3.5 Nov 17, 2015

README

An OrderedSet is a custom MutableSet that remembers its order, so that every
entry has an index that can be looked up.

Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
and released under the MIT license:

    http://code.activestate.com/recipes/576694-orderedset/

Rob Speer's changes are as follows:

    - changed the content from a doubly-linked list to a regular Python list.
      Seriously, who wants O(1) deletes but O(N) lookups by index?
    - add() returns the index of the added item
    - index() just returns the index of an item
    - added a __getstate__ and __setstate__ so it can be pickled
    - added __getitem__
    - __getitem__ and index() can be passed lists or arrays, looking up all
      the elements in them to perform NumPy-like "fancy indexing"

Tested on Python 2.6, 2.7, 3.3, 3.4, 3.5, PyPy, and PyPy3.