A MutableSet that remembers its order, so that every entry has an index.
Project description
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/
This module's changes are as follows:
-
Changed the content from a doubly-linked list to a regular Python list. The ActiveState version has O(N) lookups by index and O(1) deletion; this version has O(1) lookups by index and O(N) deletion, which seems more useful in most cases.
-
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__
andindex()
can be passed lists or arrays, looking up all the elements in them to perform NumPy-like "fancy indexing" -
The class implements the abstract base classes
collections.MutableSet
andcollections.Sequence
Tested on Python 2.7, 3.3, 3.4, 3.5, PyPy, and PyPy3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ordered-set-3.0.0.tar.gz
.
File metadata
- Download URL: ordered-set-3.0.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34399fe6aa78358aaa00129d67c65b4aa099adfc023731b1d756c85776a89bb |
|
MD5 | c8f5b99b717618803b914dd9cfe5ef43 |
|
BLAKE2b-256 | df77db7c91893e3c17587ea15f64e63f660fd27e0abd7811ae809ff2a8e0591a |