This repository was archived by the owner on Oct 13, 2024. It is now read-only.
forked from rspeer/ordered-set
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
33 lines (22 loc) · 1.26 KB
/
README
File metadata and controls
33 lines (22 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.