https://github.com/minghu6/ordered-set
A MutableSet that remembers its order, so that every entry has an index
https://github.com/minghu6/ordered-set
ordered-set python
Last synced: 29 days ago
JSON representation
A MutableSet that remembers its order, so that every entry has an index
- Host: GitHub
- URL: https://github.com/minghu6/ordered-set
- Owner: minghu6
- License: mit
- Archived: true
- Fork: true (rspeer/ordered-set)
- Created: 2016-12-24T03:49:49.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-16T02:57:40.000Z (over 3 years ago)
- Last Synced: 2025-08-31T07:26:40.180Z (5 months ago)
- Topics: ordered-set, python
- Language: Python
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: MIT-LICENSE
Awesome Lists containing this project
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"
minghu6's changes are as follow:
- restrict the OrderedSet operation object: only themselves.
Because OrderededSet's element consists of its index and value,
Python set's element only consists of its value, however.
I have written a new class OrderedSetAdapter to adapt Python set.
- writtern a new class OrderedSetAdapter
- rewrittern some contradictory method from collections.MutableSet
Tested on Python 2.7, 3.3, 3.4, 3.5, 3.6, PyPy, and PyPy3.