All Projects → grantjenks → Python Sortedcontainers

grantjenks / Python Sortedcontainers

Licence: other
Python Sorted Container Types: Sorted List, Sorted Dict, and Sorted Set

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Python Sortedcontainers

NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (-98.11%)
Mutual labels:  set, list
observable ish
Observable state and events for browser and Flutter.
Stars: ✭ 26 (-98.91%)
Mutual labels:  set, list
Collectable
High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
Stars: ✭ 233 (-90.21%)
Mutual labels:  set, list
Gods
GoDS (Go Data Structures). Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), Stacks (LinkedListStack, ArrayStack), Maps (HashMap, TreeMap, HashBidiMap, TreeBidiMap, LinkedHashMap), Trees (RedBlackTree, AVLTree, BTree, BinaryHeap), Comparators, Iterators, …
Stars: ✭ 10,883 (+357.46%)
Mutual labels:  set, list
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (-86.51%)
Mutual labels:  set, list
Gostl
Data structure and algorithm library for go, designed to provide functions similar to C++ STL
Stars: ✭ 254 (-89.32%)
Mutual labels:  set, list
php-sorted-collections
Sorted Collections for PHP
Stars: ✭ 22 (-99.08%)
Mutual labels:  set, sorted
Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+655.44%)
Mutual labels:  set, list
Learningmasteringalgorithms C
Mastering Algorithms with C 《算法精解:C语言描述》源码及Xcode工程、Linux工程
Stars: ✭ 615 (-74.15%)
Mutual labels:  set, list
Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
Stars: ✭ 125 (-94.75%)
Mutual labels:  set, list
Ruby Bookmarks
Ruby and Ruby on Rails bookmarks collection
Stars: ✭ 1,972 (-17.11%)
Mutual labels:  list
Javascriptstuff Db
Lists of JavaScript resources: tools, tutorials, starter projects, example code, etc.
Stars: ✭ 163 (-93.15%)
Mutual labels:  list
Addict
The Python Dict that's better than heroin.
Stars: ✭ 2,141 (-10%)
Mutual labels:  dict
Coc Lists
Common lists for coc.nvim
Stars: ✭ 176 (-92.6%)
Mutual labels:  list
Awesome Macos
 A curated list of awesome applications, softwares, tools and shiny things for macOS.
Stars: ✭ 12,565 (+428.16%)
Mutual labels:  list
Telegrambotslist
A list of all Telegram bots source hosted on github.
Stars: ✭ 172 (-92.77%)
Mutual labels:  list
Htaccess
✂A collection of useful .htaccess snippets.
Stars: ✭ 11,830 (+397.27%)
Mutual labels:  list
Best ai paper 2020
A curated list of the latest breakthroughs in AI by release date with a clear video explanation, link to a more in-depth article, and code
Stars: ✭ 2,140 (-10.05%)
Mutual labels:  list
Golang Set
A simple set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.
Stars: ✭ 2,168 (-8.87%)
Mutual labels:  set
Awesome Browser Extensions For Github
A collection of awesome browser extensions for GitHub.
Stars: ✭ 2,255 (-5.21%)
Mutual labels:  list

Python Sorted Containers

Sorted Containers is an Apache2 licensed sorted collections library, written in pure-Python, and fast as C-extensions.

Python's standard library is great until you need a sorted collections type. Many will attest that you can get really far without one, but the moment you really need a sorted list, sorted dict, or sorted set, you're faced with a dozen different implementations, most using C-extensions without great documentation and benchmarking.

In Python, we can do better. And we can do it in pure-Python!

>>> from sortedcontainers import SortedList
>>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
>>> sl
SortedList(['a', 'b', 'c', 'd', 'e'])
>>> sl *= 10_000_000
>>> sl.count('c')
10000000
>>> sl[-3:]
['e', 'e', 'e']
>>> from sortedcontainers import SortedDict
>>> sd = SortedDict({'c': -3, 'a': 1, 'b': 2})
>>> sd
SortedDict({'a': 1, 'b': 2, 'c': -3})
>>> sd.popitem(index=-1)
('c', -3)
>>> from sortedcontainers import SortedSet
>>> ss = SortedSet('abracadabra')
>>> ss
SortedSet(['a', 'b', 'c', 'd', 'r'])
>>> ss.bisect_left('c')
2

All of the operations shown above run in faster than linear time. The above demo also takes nearly a gigabyte of memory to run. When the sorted list is multiplied by ten million, it stores ten million references to each of "a" through "e". Each reference requires eight bytes in the sorted container. That's pretty hard to beat as it's the cost of a pointer to each object. It's also 66% less overhead than a typical binary tree implementation (e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which every node must also store two pointers to children nodes.

Sorted Containers takes all of the work out of Python sorted collections - making your deployment and use of Python easy. There's no need to install a C compiler or pre-build and distribute custom extensions. Performance is a feature and testing has 100% coverage with unit tests and hours of stress.

Testimonials

Alex Martelli, Fellow of the Python Software Foundation

"Good stuff! ... I like the simple, effective implementation idea of splitting the sorted containers into smaller "fragments" to avoid the O(N) insertion costs."

Jeff Knupp, author of Writing Idiomatic Python and Python Trainer

"That last part, "fast as C-extensions," was difficult to believe. I would need some sort of Performance Comparison to be convinced this is true. The author includes this in the docs. It is."

Kevin Samuel, Python and Django Trainer

I'm quite amazed, not just by the code quality (it's incredibly readable and has more comment than code, wow), but the actual amount of work you put at stuff that is not code: documentation, benchmarking, implementation explanations. Even the git log is clean and the unit tests run out of the box on Python 2 and 3.

Mark Summerfield, a short plea for Python Sorted Collections

Python's "batteries included" standard library seems to have a battery missing. And the argument that "we never had it before" has worn thin. It is time that Python offered a full range of collection classes out of the box, including sorted ones.

Sorted Containers is used in popular open source projects such as: Zipline, an algorithmic trading library from Quantopian; Angr, a binary analysis platform from UC Santa Barbara; Trio, an async I/O library; and Dask Distributed, a distributed computation library supported by Continuum Analytics.

Features

  • Pure-Python
  • Fully documented
  • Benchmark comparison (alternatives, runtimes, load-factors)
  • 100% test coverage
  • Hours of stress testing
  • Performance matters (often faster than C implementations)
  • Compatible API (nearly identical to older blist and bintrees modules)
  • Feature-rich (e.g. get the five largest keys in a sorted dict: d.keys()[-5:])
  • Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)
  • Developed on Python 3.7
  • Tested on CPython 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 and PyPy, PyPy3
https://api.travis-ci.org/grantjenks/python-sortedcontainers.svg?branch=master https://ci.appveyor.com/api/projects/status/github/grantjenks/python-sortedcontainers?branch=master&svg=true

Quickstart

Installing Sorted Containers is simple with pip:

$ pip install sortedcontainers

You can access documentation in the interpreter with Python's built-in help function. The help works on modules, classes and methods in Sorted Containers.

>>> import sortedcontainers
>>> help(sortedcontainers)
>>> from sortedcontainers import SortedDict
>>> help(SortedDict)
>>> help(SortedDict.popitem)

Documentation

Complete documentation for Sorted Containers is available at http://www.grantjenks.com/docs/sortedcontainers/

User Guide

The user guide provides an introduction to Sorted Containers and extensive performance comparisons and analysis.

Community Guide

The community guide provides information on the development of Sorted Containers along with support, implementation, and history details.

API Documentation

The API documentation provides information on specific functions, classes, and modules in the Sorted Containers package.

Talks

Resources

Sorted Containers License

Copyright 2014-2019 Grant Jenks

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].