├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── contributing.rst ├── history.rst ├── index.rst ├── installation.rst ├── make.bat ├── orderedset.rst ├── requirements.txt └── usage.rst ├── lib └── orderedset │ ├── __init__.py │ └── _orderedset.pyx ├── requirements.txt ├── setup.cfg ├── setup.py ├── test_requirements.txt ├── tests ├── __init__.py └── test_orderedset.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Generated C source 7 | lib/orderedset/_orderedset.c 8 | 9 | # Packages 10 | *.egg 11 | *.egg-info 12 | dist 13 | build 14 | eggs 15 | parts 16 | sdist 17 | develop-eggs 18 | .installed.cfg 19 | 20 | # Installer logs 21 | pip-log.txt 22 | 23 | # Unit test / coverage reports 24 | .coverage 25 | .tox 26 | nosetests.xml 27 | htmlcov 28 | 29 | # Translations 30 | *.mo 31 | 32 | # Mr Developer 33 | .mr.developer.cfg 34 | .project 35 | .pydevproject 36 | 37 | # Complexity 38 | output/*.html 39 | output/*/index.html 40 | 41 | # Sphinx 42 | docs/_build 43 | 44 | # mypy 45 | .mypy_cache/ 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | language: python 4 | 5 | python: 6 | - "3.8" 7 | - "3.7" 8 | - "3.6" 9 | - "3.5" 10 | - "3.4" 11 | - "2.7" 12 | 13 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 14 | install: pip install -r test_requirements.txt 15 | 16 | # command to run tests, e.g. python setup.py test 17 | script: python setup.py test 18 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Author 6 | ------ 7 | 8 | * Simon Percivall 9 | 10 | Contributors 11 | ------------ 12 | 13 | * Derived from an implementation by Raymond Hettinger 14 | * Set operations from ``abcoll.py`` in Python core. 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/simonpercivall/orderedset. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Any details about your local setup that might be helpful in troubleshooting. 21 | * Detailed steps to reproduce the bug. 22 | 23 | Fix Bugs 24 | ~~~~~~~~ 25 | 26 | Look through the GitHub issues for bugs. Anything tagged with "bug" 27 | is open to whoever wants to implement it. 28 | 29 | Implement Features 30 | ~~~~~~~~~~~~~~~~~~ 31 | 32 | Look through the GitHub issues for features. Anything tagged with "feature" 33 | is open to whoever wants to implement it. 34 | 35 | Write Documentation 36 | ~~~~~~~~~~~~~~~~~~~ 37 | 38 | Ordered Set could always use more documentation, whether as part of the 39 | official Ordered Set docs, in docstrings, or even on the web in blog posts, 40 | articles, and such. 41 | 42 | Submit Feedback 43 | ~~~~~~~~~~~~~~~ 44 | 45 | The best way to send feedback is to file an issueat https://github.com//orderedset/issues. 46 | 47 | If you are proposing a feature: 48 | 49 | * Explain in detail how it would work. 50 | * Keep the scope as narrow as possible, to make it easier to implement. 51 | * Remember that this is a volunteer-driven project, and that contributions 52 | are welcome :) 53 | 54 | Get Started! 55 | ------------ 56 | 57 | Ready to contribute? Here's how to set up `orderedset` for local development. 58 | 59 | 1. Check out the repository. 60 | 61 | 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: 62 | 63 | $ flake8 orderedset tests 64 | $ python setup.py test 65 | $ tox 66 | 67 | To get flake8 and tox, just pip install them into your virtualenv. 68 | 69 | 6. Commit and send the patch or create a pull request. 70 | 71 | Pull Request Guidelines 72 | ----------------------- 73 | 74 | Before you submit a pull request, check that it meets these guidelines: 75 | 76 | 1. The pull request should include tests. 77 | 2. If the pull request adds functionality, the docs should be updated. Put 78 | your new functionality into a function with a docstring, and add the 79 | feature to the list in README.rst. 80 | 3. The pull request should work for Python 2.7, and 3.6 81 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.0.3 - 2020-02-26 5 | ~~~~~~~~~~~~~~~~~~ 6 | 7 | * bugfix: Generate new C file to fix compile issues 8 | 9 | 2.0.2 - 2020-02-25 10 | ~~~~~~~~~~~~~~~~~~ 11 | 12 | * bugfix: Fix deprecation warning for collections.abc in Python 3.8+ 13 | 14 | 2.0.1 - 2018-03-20 15 | ~~~~~~~~~~~~~~~~~~ 16 | 17 | * bugfix: Fix `isdisjoint` to return True when the sets are disjoint 18 | * build: Include 3.6 when testing 19 | * dist: Include test files in sdist 20 | * docs: Make the Readme a bit prettier 21 | 22 | 2.0 - 2016-02-02 23 | ~~~~~~~~~~~~~~~~ 24 | 25 | * breaking change: All comparisons, other than `eq`, against other ordered sets 26 | are now performed unordered; i.e., they are treated as regular sets. 27 | * `isorderedsubset` and `isorderedsuperset` have been added to perform ordered 28 | comparisons against other sequences. Using these methods with unordered 29 | collections wield yield arbitrary (and depending on Python implementation, 30 | unstable) results. 31 | 32 | 1.2 - 2015-09-29 33 | ~~~~~~~~~~~~~~~~ 34 | 35 | * bugfix: Set operations only worked with iterables if the OrderedSet was on the 36 | left-hand side. They now work both ways. 37 | * bugfix: The order of an intersection was the right-hand side's order. It is now 38 | fixed to be the left-hand side's order. 39 | 40 | 1.1.2 - 2014-10-02 41 | ~~~~~~~~~~~~~~~~~~ 42 | 43 | * Make comparisons work with sets and lists, and not crash when compared with None. 44 | 45 | 1.1.1 - 2014-08-24 46 | ~~~~~~~~~~~~~~~~~~ 47 | 48 | * Add pickle/copy support to OrderedSet 49 | 50 | 1.1 - 2014-06-04 51 | ~~~~~~~~~~~~~~~~ 52 | 53 | * Make OrderedSets handle slicing in __getitem__(). 54 | 55 | 1.0.2 - 2014-05-14 56 | ~~~~~~~~~~~~~~~~~~ 57 | 58 | * Add proper attribution and licenses. 59 | 60 | 1.0.1 - 2014-05-13 61 | ~~~~~~~~~~~~~~~~~~ 62 | 63 | * Don't require Cython to build an sdist. 64 | 65 | 1.0 - 2014-05-11 66 | ~~~~~~~~~~~~~~~~ 67 | 68 | * First implementation. 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Simon Percivall 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of Ordered Set nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | 14 | --- 15 | 16 | Copyright (c) 2009 Raymond Hettinger 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy 19 | of this software and associated documentation files (the "Software"), to deal 20 | in the Software without restriction, including without limitation the rights 21 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | copies of the Software, and to permit persons to whom the Software is 23 | furnished to do so, subject to the following conditions: 24 | 25 | The above copyright notice and this permission notice shall be included in 26 | all copies or substantial portions of the Software. 27 | 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 34 | THE SOFTWARE. 35 | 36 | --- 37 | 38 | PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 39 | -------------------------------------------- 40 | 41 | 1. This LICENSE AGREEMENT is between the Python Software Foundation 42 | ("PSF"), and the Individual or Organization ("Licensee") accessing and 43 | otherwise using this software ("Python") in source or binary form and 44 | its associated documentation. 45 | 46 | 2. Subject to the terms and conditions of this License Agreement, PSF hereby 47 | grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, 48 | analyze, test, perform and/or display publicly, prepare derivative works, 49 | distribute, and otherwise use Python alone or in any derivative version, 50 | provided, however, that PSF's License Agreement and PSF's notice of copyright, 51 | i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 52 | 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are retained 53 | in Python alone or in any derivative version prepared by Licensee. 54 | 55 | 3. In the event Licensee prepares a derivative work that is based on 56 | or incorporates Python or any part thereof, and wants to make 57 | the derivative work available to others as provided herein, then 58 | Licensee hereby agrees to include in any such work a brief summary of 59 | the changes made to Python. 60 | 61 | 4. PSF is making Python available to Licensee on an "AS IS" 62 | basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR 63 | IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND 64 | DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS 65 | FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT 66 | INFRINGE ANY THIRD PARTY RIGHTS. 67 | 68 | 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 69 | FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS 70 | A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, 71 | OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 72 | 73 | 6. This License Agreement will automatically terminate upon a material 74 | breach of its terms and conditions. 75 | 76 | 7. Nothing in this License Agreement shall be deemed to create any 77 | relationship of agency, partnership, or joint venture between PSF and 78 | Licensee. This License Agreement does not grant permission to use PSF 79 | trademarks or trade name in a trademark sense to endorse or promote 80 | products or services of Licensee, or any third party. 81 | 82 | 8. By copying, installing or otherwise using Python, Licensee 83 | agrees to be bound by the terms and conditions of this License 84 | Agreement. 85 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | include requirements.txt 7 | include test_requirements.txt 8 | recursive-include lib *.pyx 9 | recursive-include tests *.py 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean-pyc clean-build docs clean 2 | 3 | help: 4 | @echo "clean-build - remove build artifacts" 5 | @echo "clean-pyc - remove Python file artifacts" 6 | @echo "lint - check style with flake8" 7 | @echo "test - run tests" 8 | @echo "coverage - check code coverage quickly with the default Python" 9 | @echo "docs - generate Sphinx HTML documentation, including API docs" 10 | @echo "release - package and upload a release" 11 | @echo "sdist - package" 12 | 13 | clean: clean-build clean-pyc 14 | rm -fr htmlcov/ 15 | 16 | clean-build: 17 | rm -fr build/ 18 | rm -fr lib/orderedset/*.so 19 | rm -fr lib/orderedset/*.c 20 | rm -fr lib/*.egg-info 21 | rm -fr dist/ 22 | 23 | clean-pyc: 24 | find . -name '*.pyc' -exec rm -f {} + 25 | find . -name '*.pyo' -exec rm -f {} + 26 | find . -name '*~' -exec rm -f {} + 27 | 28 | lint: 29 | flake8 lib/orderedset tests 30 | 31 | test: 32 | tox 33 | 34 | coverage: 35 | tox -e coverage 36 | 37 | docs: 38 | tox -e docs 39 | 40 | dist: clean 41 | python setup.py sdist 42 | python setup.py bdist_wheel 43 | python setup.py bdist_egg 44 | ls -l dist 45 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | Ordered Set 3 | =========== 4 | 5 | .. image:: https://badge.fury.io/py/orderedset.png 6 | :target: http://badge.fury.io/py/orderedset 7 | 8 | .. image:: https://travis-ci.org/simonpercivall/orderedset.png?branch=master 9 | :target: https://travis-ci.org/simonpercivall/orderedset 10 | 11 | .. image:: https://pypip.in/d/orderedset/badge.png 12 | :target: https://crate.io/packages/orderedset?version=latest 13 | 14 | 15 | An Ordered Set implementation in Cython. Based on `Raymond Hettinger's OrderedSet recipe`_. 16 | 17 | Example: 18 | 19 | .. code-block:: python 20 | 21 | >>> from orderedset import OrderedSet 22 | >>> oset = OrderedSet([1, 2, 3]) 23 | >>> oset 24 | OrderedSet([1, 2, 3]) 25 | >>> oset | [5, 4, 3, 2, 1] 26 | OrderedSet([1, 2, 3, 5, 4]) 27 | 28 | * Free software: BSD license 29 | * Documentation: http://orderedset.rtfd.org. 30 | 31 | Features 32 | -------- 33 | 34 | * Works like a regular set, but remembers insertion order; 35 | * Is approximately 5 times faster than the pure Python implementation overall 36 | (and 5 times slower than `set`); 37 | * Compatible with Python 2.7 through 3.8; 38 | * Supports the full set interface; 39 | * Supports some list methods, like `index` and `__getitem__`. 40 | * Supports set methods against iterables. 41 | 42 | .. _`Raymond Hettinger's OrderedSet recipe`: http://code.activestate.com/recipes/576694/ 43 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # complexity documentation build configuration file, created by 5 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 6 | # 7 | # This file is execfile()d with the current directory set to its containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys, os 16 | 17 | # If extensions (or modules to document with autodoc) are in another directory, 18 | # add these directories to sys.path here. If the directory is relative to the 19 | # documentation root, use os.path.abspath to make it absolute, like shown here. 20 | #sys.path.insert(0, os.path.abspath('.')) 21 | 22 | # Get the project root dir, which is the parent dir of this 23 | cwd = os.getcwd() 24 | project_root = os.path.dirname(cwd) 25 | 26 | # Insert the project root dir as the first element in the PYTHONPATH. 27 | # This lets us ensure that the source package is imported, and that its 28 | # version is used. 29 | sys.path.insert(0, project_root) 30 | 31 | import orderedset._orderedset 32 | 33 | # -- General configuration ----------------------------------------------------- 34 | 35 | # If your documentation needs a minimal Sphinx version, state it here. 36 | #needs_sphinx = '1.0' 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be extensions 39 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 40 | extensions = [ 41 | 'sphinx.ext.autodoc', 42 | 'sphinx.ext.viewcode', 43 | 'sphinx.ext.todo', 44 | 'sphinx.ext.intersphinx', 45 | ] 46 | 47 | # Add any paths that contain templates here, relative to this directory. 48 | templates_path = ['_templates'] 49 | 50 | # The suffix of source filenames. 51 | source_suffix = '.rst' 52 | 53 | # The encoding of source files. 54 | #source_encoding = 'utf-8-sig' 55 | 56 | # The master toctree document. 57 | master_doc = 'index' 58 | 59 | # General information about the project. 60 | project = u'Ordered Set' 61 | copyright = u'2014, Simon Percivall' 62 | 63 | # The version info for the project you're documenting, acts as replacement for 64 | # |version| and |release|, also used in various other places throughout the 65 | # built documents. 66 | # 67 | # The short X.Y version. 68 | version = orderedset.__version__ 69 | # The full version, including alpha/beta/rc tags. 70 | release = orderedset.__version__ 71 | 72 | # The language for content autogenerated by Sphinx. Refer to documentation 73 | # for a list of supported languages. 74 | #language = None 75 | 76 | # There are two options for replacing |today|: either, you set today to some 77 | # non-false value, then it is used: 78 | #today = '' 79 | # Else, today_fmt is used as the format for a strftime call. 80 | #today_fmt = '%B %d, %Y' 81 | 82 | # List of patterns, relative to source directory, that match files and 83 | # directories to ignore when looking for source files. 84 | exclude_patterns = ['_build'] 85 | 86 | # The reST default role (used for this markup: `text`) to use for all documents. 87 | #default_role = None 88 | 89 | # If true, '()' will be appended to :func: etc. cross-reference text. 90 | #add_function_parentheses = True 91 | 92 | # If true, the current module name will be prepended to all description 93 | # unit titles (such as .. function::). 94 | #add_module_names = True 95 | 96 | # If true, sectionauthor and moduleauthor directives will be shown in the 97 | # output. They are ignored by default. 98 | #show_authors = False 99 | 100 | # The name of the Pygments (syntax highlighting) style to use. 101 | pygments_style = 'sphinx' 102 | 103 | # A list of ignored prefixes for module index sorting. 104 | #modindex_common_prefix = [] 105 | 106 | # If true, keep warnings as "system message" paragraphs in the built documents. 107 | #keep_warnings = False 108 | 109 | 110 | # -- Options for HTML output --------------------------------------------------- 111 | 112 | # The theme to use for HTML and HTML Help pages. See the documentation for 113 | # a list of builtin themes. 114 | html_theme = 'sphinx_rtd_theme' 115 | 116 | # Theme options are theme-specific and customize the look and feel of a theme 117 | # further. For a list of options available for each theme, see the 118 | # documentation. 119 | #html_theme_options = {} 120 | 121 | # Add any paths that contain custom themes here, relative to this directory. 122 | import sphinx_rtd_theme 123 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 124 | 125 | # The name for this set of Sphinx documents. If None, it defaults to 126 | # " v documentation". 127 | #html_title = None 128 | 129 | # A shorter title for the navigation bar. Default is the same as html_title. 130 | #html_short_title = None 131 | 132 | # The name of an image file (relative to this directory) to place at the top 133 | # of the sidebar. 134 | #html_logo = None 135 | 136 | # The name of an image file (within the static path) to use as favicon of the 137 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 138 | # pixels large. 139 | #html_favicon = None 140 | 141 | # Add any paths that contain custom static files (such as style sheets) here, 142 | # relative to this directory. They are copied after the builtin static files, 143 | # so a file named "default.css" will overwrite the builtin "default.css". 144 | # html_static_path = ['_static'] 145 | 146 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 147 | # using the given strftime format. 148 | #html_last_updated_fmt = '%b %d, %Y' 149 | 150 | # If true, SmartyPants will be used to convert quotes and dashes to 151 | # typographically correct entities. 152 | #html_use_smartypants = True 153 | 154 | # Custom sidebar templates, maps document names to template names. 155 | #html_sidebars = {} 156 | 157 | # Additional templates that should be rendered to pages, maps page names to 158 | # template names. 159 | #html_additional_pages = {} 160 | 161 | # If false, no module index is generated. 162 | #html_domain_indices = True 163 | 164 | # If false, no index is generated. 165 | #html_use_index = True 166 | 167 | # If true, the index is split into individual pages for each letter. 168 | #html_split_index = False 169 | 170 | # If true, links to the reST sources are added to the pages. 171 | #html_show_sourcelink = True 172 | 173 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 174 | #html_show_sphinx = True 175 | 176 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 177 | #html_show_copyright = True 178 | 179 | # If true, an OpenSearch description file will be output, and all pages will 180 | # contain a tag referring to it. The value of this option must be the 181 | # base URL from which the finished HTML is served. 182 | #html_use_opensearch = '' 183 | 184 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 185 | #html_file_suffix = None 186 | 187 | # Output file base name for HTML help builder. 188 | htmlhelp_basename = 'orderedsetdoc' 189 | 190 | 191 | # -- Options for LaTeX output -------------------------------------------------- 192 | 193 | latex_elements = { 194 | # The paper size ('letterpaper' or 'a4paper'). 195 | #'papersize': 'letterpaper', 196 | 197 | # The font size ('10pt', '11pt' or '12pt'). 198 | #'pointsize': '10pt', 199 | 200 | # Additional stuff for the LaTeX preamble. 201 | #'preamble': '', 202 | } 203 | 204 | # Grouping the document tree into LaTeX files. List of tuples 205 | # (source start file, target name, title, author, documentclass [howto/manual]). 206 | latex_documents = [ 207 | ('index', 'orderedset.tex', u'Ordered Set Documentation', 208 | u'Simon Percivall', 'manual'), 209 | ] 210 | 211 | # The name of an image file (relative to this directory) to place at the top of 212 | # the title page. 213 | #latex_logo = None 214 | 215 | # For "manual" documents, if this is true, then toplevel headings are parts, 216 | # not chapters. 217 | #latex_use_parts = False 218 | 219 | # If true, show page references after internal links. 220 | #latex_show_pagerefs = False 221 | 222 | # If true, show URL addresses after external links. 223 | #latex_show_urls = False 224 | 225 | # Documents to append as an appendix to all manuals. 226 | #latex_appendices = [] 227 | 228 | # If false, no module index is generated. 229 | #latex_domain_indices = True 230 | 231 | 232 | # -- Options for manual page output -------------------------------------------- 233 | 234 | # One entry per manual page. List of tuples 235 | # (source start file, name, description, authors, manual section). 236 | man_pages = [ 237 | ('index', 'orderedset', u'Ordered Set Documentation', 238 | [u'Simon Percivall'], 1) 239 | ] 240 | 241 | # If true, show URL addresses after external links. 242 | #man_show_urls = False 243 | 244 | 245 | # -- Options for Texinfo output ------------------------------------------------ 246 | 247 | # Grouping the document tree into Texinfo files. List of tuples 248 | # (source start file, target name, title, author, 249 | # dir menu entry, description, category) 250 | texinfo_documents = [ 251 | ('index', 'orderedset', u'Ordered Set Documentation', 252 | u'Simon Percivall', 'orderedset', 'One line description of project.', 253 | 'Miscellaneous'), 254 | ] 255 | 256 | # Documents to append as an appendix to all manuals. 257 | #texinfo_appendices = [] 258 | 259 | # If false, no module index is generated. 260 | #texinfo_domain_indices = True 261 | 262 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 263 | #texinfo_show_urls = 'footnote' 264 | 265 | # If true, do not generate a @detailmenu in the "Top" node's menu. 266 | #texinfo_no_detailmenu = False 267 | 268 | 269 | intersphinx_mapping = {'python': ('http://docs.python.org/3.6', None)} 270 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. _history: 2 | 3 | ======= 4 | History 5 | ======= 6 | 7 | .. include:: ../HISTORY.rst 8 | :start-line: 3 9 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to Ordered Set's documentation! 2 | ======================================= 3 | 4 | Contents: 5 | ========= 6 | 7 | .. include:: ../README.rst 8 | :start-line: 4 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | installation 14 | usage 15 | orderedset 16 | contributing 17 | authors 18 | history 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | At the command line:: 6 | 7 | $ pip install orderedset 8 | 9 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end -------------------------------------------------------------------------------- /docs/orderedset.rst: -------------------------------------------------------------------------------- 1 | orderedset package 2 | ================== 3 | 4 | 5 | OrderedSet 6 | ---------- 7 | 8 | .. autoclass:: orderedset.OrderedSet 9 | :members: 10 | :inherited-members: 11 | 12 | .. automethod:: orderedset.OrderedSet.__getitem__(index) 13 | 14 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | sphinx_rtd_theme 3 | -r../test_requirements.txt 4 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | To use OrderedSet in a project:: 6 | 7 | from orderedset import OrderedSet 8 | 9 | oset = OrderedSet([1, 2, 3]) 10 | oset2 = OrderedSet([3, 2, 1]) 11 | oset3 = OrderedSet([1, 2, 3, 4]) 12 | 13 | oset == oset2 # False 14 | oset <= oset2 # True, same as issubset 15 | 16 | 17 | OrderedSet normally compares like a set, but can be made to make 18 | ordered sub-/superset comparisons:: 19 | 20 | oset.isorderedsubset(oset2) # False 21 | oset.isorderedsubset(oset3) # True 22 | 23 | 24 | OrderedSets work with other sets, and with lists:: 25 | 26 | from orderedset import OrderedSet 27 | 28 | oset = OrderedSet([1, 2, 3]) 29 | lst = [1, 2, 3] 30 | tes = {1, 2, 3} 31 | 32 | oset <= lst # True 33 | oset <= tes # True 34 | 35 | oset | lst # OrderedSet([1, 2, 3]) 36 | oset | tes # OrderedSet([1, 2, 3]) 37 | -------------------------------------------------------------------------------- /lib/orderedset/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | __version__ = '2.0.3' 3 | 4 | 5 | from ._orderedset import OrderedSet 6 | -------------------------------------------------------------------------------- /lib/orderedset/_orderedset.pyx: -------------------------------------------------------------------------------- 1 | # cython: embedsignature=True 2 | import sys 3 | 4 | if sys.version_info[0] == 2: 5 | from itertools import izip 6 | from collections import Set, MutableSet, Iterable 7 | else: 8 | izip = zip 9 | from collections.abc import Set, MutableSet, Iterable 10 | 11 | from cpython cimport PyDict_Contains, PyIndex_Check 12 | 13 | 14 | cdef extern from "Python.h": 15 | int PySlice_GetIndicesEx(slice, ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) except -1 16 | 17 | 18 | __all__ = ["OrderedSet"] 19 | 20 | 21 | cdef class entry: 22 | cdef object key 23 | cdef entry prev 24 | cdef entry next 25 | 26 | 27 | cdef inline void _add(_OrderedSet oset, object key): 28 | cdef entry end = oset.end 29 | cdef dict map = oset.map 30 | cdef entry next 31 | 32 | if not PyDict_Contains(map, key): 33 | next = entry() 34 | next.key, next.prev, next.next = key, end.prev, end 35 | end.prev.next = end.prev = map[key] = next 36 | oset.os_used += 1 37 | 38 | 39 | cdef void _discard(_OrderedSet oset, object key): 40 | cdef dict map = oset.map 41 | cdef entry _entry 42 | 43 | if PyDict_Contains(map, key): 44 | _entry = map.pop(key) 45 | _entry.prev.next = _entry.next 46 | _entry.next.prev = _entry.prev 47 | oset.os_used -= 1 48 | 49 | 50 | cdef inline object _isorderedsubset(seq1, seq2): 51 | if not len(seq1) <= len(seq2): 52 | return False 53 | for self_elem, other_elem in izip(seq1, seq2): 54 | if not self_elem == other_elem: 55 | return False 56 | return True 57 | 58 | 59 | cdef class OrderedSetIterator(object): 60 | cdef _OrderedSet oset 61 | cdef entry curr 62 | cdef ssize_t si_used 63 | 64 | def __cinit__(self, _OrderedSet oset): 65 | self.oset = oset 66 | self.curr = oset.end 67 | self.si_used = oset.os_used 68 | 69 | def __iter__(self): 70 | return self 71 | 72 | def __next__(self): 73 | cdef entry item 74 | 75 | if self.si_used != self.oset.os_used: 76 | # make this state sticky 77 | self.si_used = -1 78 | raise RuntimeError('%s changed size during iteration' % type(self.oset).__name__) 79 | 80 | item = self.curr.next 81 | if item == self.oset.end: 82 | raise StopIteration() 83 | self.curr = item 84 | return item.key 85 | 86 | 87 | cdef class OrderedSetReverseIterator(object): 88 | cdef _OrderedSet oset 89 | cdef entry curr 90 | cdef ssize_t si_used 91 | 92 | def __cinit__(self, _OrderedSet oset): 93 | self.oset = oset 94 | self.curr = oset.end 95 | self.si_used = oset.os_used 96 | 97 | def __iter__(self): 98 | return self 99 | 100 | def __next__(self): 101 | cdef entry item 102 | 103 | if self.si_used != self.oset.os_used: 104 | # make this state sticky 105 | self.si_used = -1 106 | raise RuntimeError('%s changed size during iteration' % type(self.oset).__name__) 107 | 108 | item = self.curr.prev 109 | if item is self.oset.end: 110 | raise StopIteration() 111 | self.curr = item 112 | return item.key 113 | 114 | 115 | cdef class _OrderedSet(object): 116 | cdef dict map 117 | cdef entry end 118 | cdef ssize_t os_used 119 | 120 | def __cinit__(self): 121 | self.map = {} 122 | self.os_used = 0 123 | self.end = end = entry() 124 | end.prev = end.next = end 125 | 126 | def __init__(self, object iterable=None): 127 | cdef dict map = self.map 128 | cdef entry end = self.end 129 | cdef entry next 130 | 131 | if iterable is not None: 132 | for elem in iterable: 133 | if not PyDict_Contains(map, elem): 134 | next = entry() 135 | next.key, next.prev, next.next = elem, end.prev, end 136 | end.prev.next = end.prev = map[elem] = next 137 | self.os_used += 1 138 | 139 | @classmethod 140 | def _from_iterable(cls, it): 141 | return cls(it) 142 | 143 | ## 144 | # set methods 145 | ## 146 | cpdef add(self, elem): 147 | """Add element `elem` to the set.""" 148 | _add(self, elem) 149 | 150 | cpdef discard(self, elem): 151 | """Remove element `elem` from the ``OrderedSet`` if it is present.""" 152 | _discard(self, elem) 153 | 154 | cpdef pop(self, last=True): 155 | """Remove last element. Raises ``KeyError`` if the ``OrderedSet`` is empty.""" 156 | if not self: 157 | raise KeyError('OrderedSet is empty') 158 | key = self.end.prev.key if last else self.end.next.key 159 | _discard(self, key) 160 | return key 161 | 162 | def remove(self, elem): 163 | """ 164 | Remove element `elem` from the ``set``. 165 | Raises :class:`KeyError` if `elem` is not contained in the set. 166 | """ 167 | if elem not in self: 168 | raise KeyError(elem) 169 | _discard(self, elem) 170 | 171 | def clear(self): 172 | """Remove all elements from the `set`.""" 173 | cdef entry end = self.end 174 | end.next.prev = end.next = None 175 | 176 | # reinitialize 177 | self.map = {} 178 | self.os_used = 0 179 | self.end = end = entry() 180 | end.prev = end.next = end 181 | 182 | def copy(self): 183 | """ 184 | :rtype: OrderedSet 185 | :return: a new ``OrderedSet`` with a shallow copy of self. 186 | """ 187 | return self._from_iterable(self) 188 | 189 | def difference(self, other): 190 | """``OrderedSet - other`` 191 | 192 | :rtype: OrderedSet 193 | :return: a new ``OrderedSet`` with elements in the set that are not in the others. 194 | """ 195 | return self - other 196 | 197 | def difference_update(self, other): 198 | """``OrderedSet -= other`` 199 | 200 | Update the ``OrderedSet``, removing elements found in others. 201 | """ 202 | self -= other 203 | 204 | def __sub__(self, other): 205 | """ 206 | :rtype: OrderedSet 207 | """ 208 | ostyp = type(self if isinstance(self, OrderedSet) else other) 209 | 210 | if not isinstance(self, Iterable): 211 | return NotImplemented 212 | if not isinstance(other, Set): 213 | if not isinstance(other, Iterable): 214 | return NotImplemented 215 | other = ostyp._from_iterable(other) 216 | 217 | return ostyp._from_iterable(value for value in self if value not in other) 218 | 219 | def __isub__(self, other): 220 | if other is self: 221 | self.clear() 222 | else: 223 | for value in other: 224 | self.discard(value) 225 | return self 226 | 227 | def intersection(self, other): 228 | """``OrderedSet & other`` 229 | 230 | :rtype: OrderedSet 231 | :return: a new ``OrderedSet`` with elements common to the set and all others. 232 | """ 233 | return self & other 234 | 235 | def intersection_update(self, other): 236 | """``OrderedSet &= other`` 237 | 238 | Update the ``OrderedSet``, keeping only elements found in it and all others. 239 | """ 240 | self &= other 241 | 242 | def __and__(self, other): 243 | """ 244 | :rtype: OrderedSet 245 | """ 246 | ostyp = type(self if isinstance(self, OrderedSet) else other) 247 | 248 | if not isinstance(self, Iterable): 249 | return NotImplemented 250 | if not isinstance(other, Set): 251 | if not isinstance(other, Iterable): 252 | return NotImplemented 253 | other = ostyp._from_iterable(other) 254 | 255 | return ostyp._from_iterable(value for value in self if value in other) 256 | 257 | def __iand__(self, it): 258 | for value in (self - it): 259 | self.discard(value) 260 | return self 261 | 262 | def isdisjoint(self, other): 263 | """ 264 | Return True if the set has no elements in common with other. 265 | Sets are disjoint if and only if their intersection is the empty set. 266 | 267 | :rtype: bool 268 | """ 269 | for value in other: 270 | if value in self: 271 | return False 272 | return True 273 | 274 | def issubset(self, other): 275 | """``OrderedSet <= other`` 276 | 277 | :rtype: bool 278 | 279 | Test whether the ``OrderedSet`` is a proper subset of other, that is, 280 | ``OrderedSet <= other and OrderedSet != other``. 281 | """ 282 | return self <= other 283 | 284 | def issuperset(self, other): 285 | """``OrderedSet >= other`` 286 | 287 | :rtype: bool 288 | 289 | Test whether every element in other is in the set. 290 | """ 291 | return other <= self 292 | 293 | def isorderedsubset(self, other): 294 | return _isorderedsubset(self, other) 295 | 296 | def isorderedsuperset(self, other): 297 | return _isorderedsubset(other, self) 298 | 299 | def symmetric_difference(self, other): 300 | """``OrderedSet ^ other`` 301 | 302 | :rtype: OrderedSet 303 | :return: a new ``OrderedSet`` with elements in either the set or other but not both. 304 | """ 305 | return self ^ other 306 | 307 | def symmetric_difference_update(self, other): 308 | """``OrderedSet ^= other`` 309 | 310 | Update the ``OrderedSet``, keeping only elements found in either set, but not in both. 311 | """ 312 | self ^= other 313 | 314 | def __xor__(self, other): 315 | """ 316 | :rtype: OrderedSet 317 | """ 318 | if not isinstance(self, Iterable): 319 | return NotImplemented 320 | if not isinstance(other, Iterable): 321 | return NotImplemented 322 | 323 | return (self - other) | (other - self) 324 | 325 | def __ixor__(self, other): 326 | if other is self: 327 | self.clear() 328 | else: 329 | if not isinstance(other, Set): 330 | other = self._from_iterable(other) 331 | for value in other: 332 | if value in self: 333 | self.discard(value) 334 | else: 335 | self.add(value) 336 | return self 337 | 338 | def union(self, other): 339 | """``OrderedSet | other`` 340 | 341 | :rtype: OrderedSet 342 | :return: a new ``OrderedSet`` with elements from the set and all others. 343 | """ 344 | return self | other 345 | 346 | def update(self, other): 347 | """``OrderedSet |= other`` 348 | 349 | Update the ``OrderedSet``, adding elements from all others. 350 | """ 351 | self |= other 352 | 353 | def __or__(self, other): 354 | """ 355 | :rtype: OrderedSet 356 | """ 357 | ostyp = type(self if isinstance(self, OrderedSet) else other) 358 | 359 | if not isinstance(self, Iterable): 360 | return NotImplemented 361 | if not isinstance(other, Iterable): 362 | return NotImplemented 363 | chain = (e for s in (self, other) for e in s) 364 | return ostyp._from_iterable(chain) 365 | 366 | def __ior__(self, other): 367 | for elem in other: 368 | _add(self, elem) 369 | return self 370 | 371 | ## 372 | # list methods 373 | ## 374 | def index(self, elem): 375 | """Return the index of `elem`. Rases :class:`ValueError` if not in the OrderedSet.""" 376 | if elem not in self: 377 | raise ValueError("%s is not in %s" % (elem, type(self).__name__)) 378 | cdef entry curr = self.end.next 379 | cdef ssize_t index = 0 380 | while curr.key != elem: 381 | curr = curr.next 382 | index += 1 383 | return index 384 | 385 | cdef _getslice(self, slice item): 386 | cdef ssize_t start, stop, step, slicelength, place, i 387 | cdef entry curr 388 | cdef _OrderedSet result 389 | PySlice_GetIndicesEx(item, len(self), &start, &stop, &step, &slicelength) 390 | 391 | result = type(self)() 392 | place = start 393 | curr = self.end 394 | 395 | if slicelength <= 0: 396 | pass 397 | elif step > 0: 398 | # normal forward slice 399 | i = 0 400 | while slicelength > 0: 401 | while i <= place: 402 | curr = curr.next 403 | i += 1 404 | _add(result, curr.key) 405 | place += step 406 | slicelength -= 1 407 | else: 408 | # we're going backwards 409 | i = len(self) 410 | while slicelength > 0: 411 | while i > place: 412 | curr = curr.prev 413 | i -= 1 414 | _add(result, curr.key) 415 | place += step 416 | slicelength -= 1 417 | return result 418 | 419 | cdef _getindex(self, ssize_t index): 420 | cdef ssize_t _len = len(self) 421 | if index >= _len or (index < 0 and abs(index) > _len): 422 | raise IndexError("list index out of range") 423 | 424 | cdef entry curr 425 | if index >= 0: 426 | curr = self.end.next 427 | while index: 428 | curr = curr.next 429 | index -= 1 430 | else: 431 | index = abs(index) - 1 432 | curr = self.end.prev 433 | while index: 434 | curr = curr.prev 435 | index -= 1 436 | return curr.key 437 | 438 | def __getitem__(self, item): 439 | """Return the `elem` at `index`. Raises :class:`IndexError` if `index` is out of range.""" 440 | if isinstance(item, slice): 441 | return self._getslice(item) 442 | if not PyIndex_Check(item): 443 | raise TypeError("%s indices must be integers, not %s" % (type(self).__name__, type(item))) 444 | return self._getindex(item) 445 | 446 | ## 447 | # sequence methods 448 | ## 449 | def __len__(self): 450 | return len(self.map) 451 | 452 | def __contains__(self, elem): 453 | return elem in self.map 454 | 455 | def __iter__(self): 456 | return OrderedSetIterator(self) 457 | 458 | def __reversed__(self): 459 | return OrderedSetReverseIterator(self) 460 | 461 | def __reduce__(self): 462 | items = list(self) 463 | inst_dict = vars(self).copy() 464 | return self.__class__, (items, ), inst_dict 465 | 466 | 467 | class OrderedSet(_OrderedSet, MutableSet): 468 | """ 469 | An ``OrderedSet`` object is an ordered collection of distinct hashable objects. 470 | 471 | It works like the :class:`set` type, but remembers insertion order. 472 | 473 | It also supports :meth:`__getitem__` and :meth:`index`, like the 474 | :class:`list` type. 475 | """ 476 | def __repr__(self): 477 | if not self: 478 | return '%s()' % (self.__class__.__name__,) 479 | return '%s(%r)' % (self.__class__.__name__, list(self)) 480 | 481 | def __eq__(self, other): 482 | if isinstance(other, (_OrderedSet, list)): 483 | return len(self) == len(other) and list(self) == list(other) 484 | elif isinstance(other, Set): 485 | return set(self) == set(other) 486 | return NotImplemented 487 | 488 | def __le__(self, other): 489 | if isinstance(other, Set): 490 | return len(self) <= len(other) and set(self) <= set(other) 491 | elif isinstance(other, list): 492 | return len(self) <= len(other) and list(self) <= list(other) 493 | return NotImplemented 494 | 495 | def __lt__(self, other): 496 | if isinstance(other, Set): 497 | return len(self) < len(other) and set(self) < set(other) 498 | elif isinstance(other, list): 499 | return len(self) < len(other) and list(self) < list(other) 500 | return NotImplemented 501 | 502 | def __ge__(self, other): 503 | ret = self < other 504 | if ret is NotImplemented: 505 | return ret 506 | return not ret 507 | 508 | def __gt__(self, other): 509 | ret = self <= other 510 | if ret is NotImplemented: 511 | return ret 512 | return not ret 513 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonpercivall/orderedset/3ea350acfa3b698427e7950527d8cad15a3e8f2b/requirements.txt -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import sys 4 | import os 5 | import re 6 | from setuptools import setup, find_packages, Extension 7 | 8 | 9 | readme = open('README.rst').read() 10 | history = open('HISTORY.rst').read() 11 | 12 | 13 | def read_reqs(name): 14 | with open(os.path.join(os.path.dirname(__file__), name)) as f: 15 | return [line for line in f.read().split('\n') if line and not line.strip().startswith('#')] 16 | 17 | 18 | def read_version(): 19 | with open(os.path.join('lib', 'orderedset', '__init__.py')) as f: 20 | m = re.search(r'''__version__\s*=\s*['"]([^'"]*)['"]''', f.read()) 21 | if m: 22 | return m.group(1) 23 | raise ValueError("couldn't find version") 24 | 25 | 26 | try: 27 | from Cython.Build import cythonize 28 | extensions = cythonize(Extension('orderedset._orderedset', 29 | ['lib/orderedset/_orderedset.pyx'])) 30 | except ImportError: 31 | # couldn't import Cython, try with the .c file 32 | extensions = [Extension('orderedset._orderedset', 33 | ['lib/orderedset/_orderedset.c'])] 34 | 35 | 36 | tests_require = [] 37 | if sys.version_info < (2, 7): 38 | tests_require.append("unittest2") 39 | 40 | 41 | # NB: _don't_ add namespace_packages to setup(), it'll break 42 | # everything using imp.find_module 43 | setup( 44 | name='orderedset', 45 | version=read_version(), 46 | description='An Ordered Set implementation in Cython.', 47 | long_description=readme + '\n\n' + history, 48 | author='Simon Percivall', 49 | author_email='percivall@gmail.com', 50 | url='https://github.com/simonpercivall/orderedset', 51 | packages=find_packages('lib'), 52 | package_dir={'': 'lib'}, 53 | ext_modules=extensions, 54 | include_package_data=False, 55 | install_requires=read_reqs('requirements.txt'), 56 | license="BSD", 57 | zip_safe=False, 58 | keywords='orderedset', 59 | classifiers=[ 60 | 'Development Status :: 4 - Beta', 61 | 'Intended Audience :: Developers', 62 | 'License :: OSI Approved :: BSD License', 63 | 'Natural Language :: English', 64 | "Programming Language :: Python :: 2", 65 | 'Programming Language :: Python :: 2.7', 66 | 'Programming Language :: Python :: 3', 67 | 'Programming Language :: Python :: 3.4', 68 | 'Programming Language :: Python :: 3.5', 69 | 'Programming Language :: Python :: 3.6', 70 | 'Programming Language :: Python :: 3.7', 71 | 'Programming Language :: Python :: 3.8', 72 | ], 73 | tests_require=tests_require, 74 | test_suite='tests', 75 | ) 76 | -------------------------------------------------------------------------------- /test_requirements.txt: -------------------------------------------------------------------------------- 1 | Cython >= 0.20.1 2 | coverage == 3.7.1 3 | -rrequirements.txt 4 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | -------------------------------------------------------------------------------- /tests/test_orderedset.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_orderedset 6 | ---------------------------------- 7 | 8 | Tests for `orderedset` module. 9 | """ 10 | import sys 11 | 12 | if sys.version_info < (2, 7): 13 | import unittest2 as unittest 14 | else: 15 | import unittest 16 | import weakref 17 | import gc 18 | import copy 19 | import pickle 20 | 21 | from orderedset import * 22 | 23 | 24 | class TestOrderedset(unittest.TestCase): 25 | 26 | def setUp(self): 27 | self.lst = list(range(10)) 28 | 29 | def test_add_new(self): 30 | oset = OrderedSet(self.lst) 31 | lst = self.lst 32 | 33 | item = 10 34 | lst.append(item) 35 | oset.add(item) 36 | 37 | self.assertEqual(list(oset), lst) 38 | 39 | def test_add_existing(self): 40 | oset = OrderedSet(self.lst) 41 | lst = self.lst 42 | 43 | oset.add(1) 44 | oset.add(3) 45 | self.assertEqual(list(oset), lst) 46 | 47 | def test_discard(self): 48 | oset = OrderedSet([1, 2, 3]) 49 | 50 | oset.discard(1) 51 | self.assertNotIn(1, oset) 52 | 53 | oset.discard(4) 54 | 55 | def test_pop(self): 56 | oset = OrderedSet([1, 2, 3]) 57 | 58 | v = oset.pop() 59 | self.assertEqual(v, 3) 60 | self.assertNotIn(v, oset) 61 | 62 | v = oset.pop(last=False) 63 | self.assertEqual(v, 1) 64 | self.assertNotIn(v, oset) 65 | 66 | def test_remove(self): 67 | oset = OrderedSet(self.lst) 68 | lst = self.lst 69 | 70 | oset.remove(3) 71 | lst.remove(3) 72 | 73 | self.assertEqual(list(oset), lst) 74 | 75 | def test_clear(self): 76 | val = frozenset([1]) 77 | 78 | oset = OrderedSet() 79 | ws = weakref.WeakKeyDictionary() 80 | 81 | oset.add(val) 82 | ws[val] = 1 83 | oset.clear() 84 | 85 | self.assertEqual(list(oset), []) 86 | 87 | del val 88 | gc.collect() 89 | self.assertEqual(list(ws), []) 90 | 91 | def test_copy(self): 92 | oset1 = OrderedSet(self.lst) 93 | oset2 = oset1.copy() 94 | 95 | self.assertIsNot(oset1, oset2) 96 | self.assertEqual(oset1, oset2) 97 | 98 | oset1.clear() 99 | self.assertNotEqual(oset1, oset2) 100 | 101 | def test_reduce(self): 102 | oset = OrderedSet(self.lst) 103 | oset2 = copy.copy(oset) 104 | self.assertEqual(oset, oset2) 105 | 106 | oset3 = pickle.loads(pickle.dumps(oset)) 107 | self.assertEqual(oset, oset3) 108 | 109 | oset.add(-1) 110 | self.assertNotEqual(oset, oset2) 111 | 112 | def test_difference_and_update(self): 113 | oset1 = OrderedSet([1, 2, 3]) 114 | oset2 = OrderedSet([3, 4, 5]) 115 | 116 | oset3 = oset1 - oset2 117 | self.assertEqual(oset3, OrderedSet([1, 2])) 118 | 119 | self.assertEqual(oset1.difference(oset2), oset3) 120 | 121 | oset4 = oset1.copy() 122 | oset4 -= oset2 123 | self.assertEqual(oset4, oset3) 124 | 125 | oset5 = oset1.copy() 126 | oset5.difference_update(oset2) 127 | self.assertEqual(oset5, oset3) 128 | 129 | def test_intersection_and_update(self): 130 | oset1 = OrderedSet([1, 2, 3]) 131 | oset2 = OrderedSet([3, 4, 5]) 132 | 133 | oset3 = oset1 & oset2 134 | self.assertEqual(oset3, OrderedSet([3])) 135 | 136 | oset4 = oset1.copy() 137 | oset4 &= oset2 138 | 139 | self.assertEqual(oset4, oset3) 140 | 141 | oset5 = oset1.copy() 142 | oset5.intersection_update(oset2) 143 | self.assertEqual(oset5, oset3) 144 | 145 | def test_issubset(self): 146 | oset1 = OrderedSet([1, 2, 3]) 147 | oset2 = OrderedSet([1, 2]) 148 | 149 | self.assertTrue(oset2 < oset1) 150 | self.assertTrue(oset2.issubset(oset1)) 151 | 152 | oset2 = OrderedSet([1, 2, 3]) 153 | self.assertTrue(oset2 <= oset1) 154 | self.assertTrue(oset1 <= oset2) 155 | self.assertTrue(oset2.issubset(oset1)) 156 | 157 | oset2 = OrderedSet([1, 2, 3, 4]) 158 | self.assertFalse(oset2 < oset1) 159 | self.assertFalse(oset2.issubset(oset1)) 160 | self.assertTrue(oset1 < oset2) 161 | 162 | # issubset compares underordered for all sets 163 | oset2 = OrderedSet([4, 3, 2, 1]) 164 | self.assertTrue(oset1 < oset2) 165 | 166 | def test_issuperset(self): 167 | oset1 = OrderedSet([1, 2, 3]) 168 | oset2 = OrderedSet([1, 2]) 169 | 170 | self.assertTrue(oset1 > oset2) 171 | self.assertTrue(oset1.issuperset(oset2)) 172 | 173 | oset2 = OrderedSet([1, 2, 3]) 174 | self.assertTrue(oset1 >= oset2) 175 | self.assertTrue(oset2 >= oset1) 176 | self.assertTrue(oset1.issubset(oset2)) 177 | 178 | oset2 = OrderedSet([1, 2, 3, 4]) 179 | self.assertFalse(oset1 > oset2) 180 | self.assertFalse(oset1.issuperset(oset2)) 181 | self.assertTrue(oset2 > oset1) 182 | 183 | # issubset compares underordered for all sets 184 | oset2 = OrderedSet([4, 3, 2, 1]) 185 | self.assertTrue(oset2 > oset1) 186 | 187 | def test_orderedsubset(self): 188 | oset1 = OrderedSet([1, 2, 3]) 189 | oset2 = OrderedSet([1, 2, 3, 4]) 190 | oset3 = OrderedSet([1, 2, 4, 3]) 191 | 192 | self.assertTrue(oset1.isorderedsubset(oset2)) 193 | self.assertFalse(oset1.isorderedsubset(oset3)) 194 | self.assertFalse(oset2.isorderedsubset(oset3)) 195 | 196 | def test_orderedsuperset(self): 197 | oset1 = OrderedSet([1, 2, 3]) 198 | oset2 = OrderedSet([1, 2, 3, 4]) 199 | oset3 = OrderedSet([1, 2, 4, 3]) 200 | 201 | self.assertTrue(oset2.isorderedsuperset(oset1)) 202 | self.assertFalse(oset3.isorderedsuperset(oset1)) 203 | self.assertFalse(oset3.isorderedsuperset(oset2)) 204 | 205 | def test_symmetric_difference_and_update(self): 206 | oset1 = OrderedSet([1, 2, 3]) 207 | oset2 = OrderedSet([2, 3, 4]) 208 | 209 | oset3 = oset1 ^ oset2 210 | self.assertEqual(oset3, OrderedSet([1, 4])) 211 | 212 | oset4 = oset1.copy() 213 | self.assertEqual(oset4.symmetric_difference(oset2), oset3) 214 | 215 | oset4 ^= oset2 216 | self.assertEqual(oset4, oset3) 217 | 218 | oset5 = oset1.copy() 219 | oset5.symmetric_difference_update(oset2) 220 | self.assertEqual(oset5, oset3) 221 | 222 | def test_union_and_update(self): 223 | oset = OrderedSet(self.lst) 224 | lst = self.lst 225 | 226 | oset2 = oset | [3, 9, 27] 227 | self.assertEqual(oset2, lst + [27]) 228 | 229 | # make sure original oset isn't changed 230 | self.assertEqual(oset, lst) 231 | 232 | oset1 = OrderedSet(self.lst) 233 | oset2 = OrderedSet(self.lst) 234 | 235 | oset3 = oset1 | oset2 236 | self.assertEqual(oset3, oset1) 237 | 238 | self.assertEqual(oset3, oset1.union(oset2)) 239 | 240 | oset1 |= OrderedSet("abc") 241 | self.assertEqual(oset1, oset2 | "abc") 242 | 243 | oset1 = OrderedSet(self.lst) 244 | oset1.update("abc") 245 | self.assertEqual(oset1, oset2 | "abc") 246 | 247 | def test_union_with_iterable(self): 248 | oset1 = OrderedSet([1]) 249 | 250 | self.assertEqual(oset1 | [2, 1], OrderedSet([1, 2])) 251 | self.assertEqual([2] | oset1, OrderedSet([2, 1])) 252 | self.assertEqual([1, 2] | OrderedSet([3, 1, 2, 4]), OrderedSet([1, 2, 3, 4])) 253 | 254 | # union with unordered set should work, though the order will be arbitrary 255 | self.assertEqual(oset1 | set([2]), OrderedSet([1, 2])) 256 | self.assertEqual(set([2]) | oset1, OrderedSet([2, 1])) 257 | 258 | def test_symmetric_difference_with_iterable(self): 259 | oset1 = OrderedSet([1]) 260 | 261 | self.assertEqual(oset1 ^ [1], OrderedSet([])) 262 | self.assertEqual([1] ^ oset1, OrderedSet([])) 263 | 264 | self.assertEqual(OrderedSet([3, 1, 4, 2]) ^ [3, 4], OrderedSet([1, 2])) 265 | self.assertEqual([3, 1, 4, 2] ^ OrderedSet([3, 4]), OrderedSet([1, 2])) 266 | 267 | self.assertEqual(OrderedSet([3, 1, 4, 2]) ^ set([3, 4]), OrderedSet([1, 2])) 268 | self.assertEqual(set([3, 1, 4]) ^ OrderedSet([3, 4, 2]), OrderedSet([1, 2])) 269 | 270 | def test_intersection_with_iterable(self): 271 | self.assertEqual([1, 2, 3] & OrderedSet([3, 2]), OrderedSet([2, 3])) 272 | self.assertEqual(OrderedSet([3, 2] & OrderedSet([1, 2, 3])), OrderedSet([3, 2])) 273 | 274 | def test_difference_with_iterable(self): 275 | self.assertEqual(OrderedSet([1, 2, 3, 4]) - [3, 2], OrderedSet([1, 4])) 276 | self.assertEqual([3, 2, 4, 1] - OrderedSet([2, 4]), OrderedSet([3, 1])) 277 | 278 | def test_isdisjoint(self): 279 | self.assertTrue(OrderedSet().isdisjoint(OrderedSet())) 280 | self.assertTrue(OrderedSet([1]).isdisjoint(OrderedSet([2]))) 281 | self.assertFalse(OrderedSet([1, 2]).isdisjoint(OrderedSet([2, 3]))) 282 | 283 | def test_index(self): 284 | oset = OrderedSet("abcd") 285 | self.assertEqual(oset.index("b"), 1) 286 | 287 | def test_getitem(self): 288 | oset = OrderedSet("abcd") 289 | self.assertEqual(oset[2], "c") 290 | 291 | def test_getitem_slice(self): 292 | oset = OrderedSet("abcdef") 293 | self.assertEqual(oset[:2], OrderedSet("ab")) 294 | self.assertEqual(oset[2:], OrderedSet("cdef")) 295 | self.assertEqual(oset[::-1], OrderedSet("fedcba")) 296 | self.assertEqual(oset[1:-1:2], OrderedSet("bd")) 297 | self.assertEqual(oset[1::2], OrderedSet("bdf")) 298 | 299 | def test_len(self): 300 | oset = OrderedSet(self.lst) 301 | self.assertEqual(len(oset), len(self.lst)) 302 | 303 | oset.remove(0) 304 | self.assertEqual(len(oset), len(self.lst) - 1) 305 | 306 | def test_contains(self): 307 | oset = OrderedSet(self.lst) 308 | self.assertTrue(1 in oset) 309 | 310 | def test_iter_mutated(self): 311 | oset = OrderedSet(self.lst) 312 | it = iter(oset) 313 | oset.add('a') 314 | 315 | with self.assertRaises(RuntimeError): 316 | next(it) 317 | 318 | it = reversed(oset) 319 | oset.add('b') 320 | 321 | with self.assertRaises(RuntimeError): 322 | next(it) 323 | 324 | def test_iter_and_valid_order(self): 325 | oset = OrderedSet(self.lst) 326 | self.assertEqual(list(oset), self.lst) 327 | 328 | oset = OrderedSet(self.lst + self.lst) 329 | self.assertEqual(list(oset), self.lst) 330 | 331 | def test_reverse_order(self): 332 | oset = OrderedSet(self.lst) 333 | self.assertEqual(list(reversed(oset)), list(reversed(self.lst))) 334 | 335 | def test_repr(self): 336 | oset = OrderedSet([1]) 337 | self.assertEqual(repr(oset), "OrderedSet([1])") 338 | 339 | def test_eq(self): 340 | oset1 = OrderedSet(self.lst) 341 | oset2 = OrderedSet(self.lst) 342 | 343 | self.assertNotEqual(oset1, None) 344 | 345 | self.assertEqual(oset1, oset2) 346 | self.assertEqual(oset1, set(self.lst)) 347 | self.assertEqual(oset1, list(self.lst)) 348 | 349 | def test_ordering(self): 350 | oset1 = OrderedSet(self.lst) 351 | oset2 = OrderedSet(self.lst) 352 | 353 | if sys.version_info < (3, 0): 354 | self.assertFalse(oset1 <= None) 355 | 356 | self.assertLessEqual(oset2, oset1) 357 | self.assertLessEqual(oset2, set(oset1)) 358 | self.assertLessEqual(oset2, list(oset1)) 359 | 360 | self.assertGreaterEqual(oset1, oset2) 361 | self.assertGreaterEqual(oset1, set(oset2)) 362 | self.assertGreaterEqual(oset1, list(oset2)) 363 | 364 | oset3 = OrderedSet(self.lst[:-1]) 365 | 366 | self.assertLess(oset3, oset1) 367 | self.assertLess(oset3, set(oset1)) 368 | self.assertLess(oset3, list(oset1)) 369 | 370 | self.assertGreater(oset1, oset3) 371 | self.assertGreater(oset1, set(oset3)) 372 | self.assertGreater(oset1, list(oset3)) 373 | 374 | 375 | if __name__ == '__main__': 376 | unittest.main() 377 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py34, py35, py36, py37, py38 3 | 4 | [testenv] 5 | commands = {envpython} setup.py test 6 | deps = -rtest_requirements.txt 7 | 8 | [testenv:py26] 9 | setenv = 10 | CFLAGS =-Qunused-arguments 11 | CPPFLAGS =-Qunused-arguments 12 | 13 | [testenv:docs] 14 | basepython = python2.7 15 | usedevelop = True 16 | commands = 17 | rm -f docs/orderedset*.rst 18 | sphinx-apidoc -T -o docs/ lib 19 | make -C docs clean 20 | make -C docs html 21 | whitelist_externals = 22 | make 23 | rm 24 | deps = 25 | -rdocs/requirements.txt 26 | 27 | [testenv:coverage] 28 | usedevelop = True 29 | basepython = python2.7 30 | commands = 31 | coverage run --source orderedset setup.py test 32 | coverage report -m 33 | coverage html 34 | deps = 35 | -rtest_requirements.txt 36 | 37 | [testenv:ipython] 38 | basepython = python2.7 39 | usedevelop = True 40 | commands = ipython 41 | deps = 42 | ipython 43 | -rtest_requirements.txt 44 | --------------------------------------------------------------------------------