Skip to main content

a list-like type with better asymptotic performance and similar performance on small lists

Project description

The BList is a type that looks, acts, and quacks like a Python list, but has better performance for many (but not all) use cases. The use cases where the BList is slightly slower than Python’s list are as follows (O(log n) vs. O(1)):

  1. A large list that never changes length.

  2. A large lists where inserts and deletes are only at the end of the list (LIFO).

With that disclaimer out of the way, here are some of the use cases where the BLists is dramatically faster than the built-in list:

  1. Insertion into or removal from a large list (O(log n) vs. O(n))

  2. Taking large slices of large lists (O(log n) vs O(n))

  3. Making shallow copies of large lists (O(1) vs. O(n))

  4. Changing large slices of large lists (O(log n + log k) vs. O(n + k))

  5. Multiplying a list to make a large, sparse list (O(log k) vs. O(kn))

You’ve probably noticed that we keep referring to “large lists”. For small lists, BLists and the built-in list have very similar performance.

So you can see the performance of the BList in more detail, several performance graphs available at the following link: http://stutzbachenterprises.com/blist/

Example usage:

>>> from blist import *
>>> x = blist([0])             # x is a BList with one element
>>> x *= 2**29                 # x is a BList with > 500 million elements
>>> x.append(5)                # append to x
>>> y = x[4:-234234]           # Take a 500 million element slice from x
>>> del x[3:1024]              # Delete a few thousand elements from x

For comparison, on most systems the built-in list just raises MemoryError and calls it a day.

The BList has two key features that allow it to pull off this performance:

  1. Internally, a B+Tree is a wide, squat tree. Each node has a maximum of 128 children. If the entire list contains 128 or fewer objects, then there is only one node, which simply contains an array of the objects. In other words, for short lists, a BList works just like Python’s array-based list() type. Thus, it has the same good performance on small lists.

  2. The BList type features transparent copy-on-write. If a non-root node needs to be copied (as part of a getslice, copy, setslice, etc.), the node is shared between multiple parents instead of being copied. If it needs to be modified later, it will be copied at that time. This is completely behind-the-scenes; from the user’s point of view, the BList works just like a regular Python list.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blist-0.9.4.tar.gz (75.0 kB view details)

Uploaded Source

Built Distributions

blist-0.9.4-py2.5-win32.egg (20.3 kB view details)

Uploaded Egg

blist-0.9.4-py2.5-linux-i686.egg (83.5 kB view details)

Uploaded Egg

blist-0.9.4-py2.5-cygwin-1.5.23-i686.egg (76.7 kB view details)

Uploaded Egg

File details

Details for the file blist-0.9.4.tar.gz.

File metadata

  • Download URL: blist-0.9.4.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for blist-0.9.4.tar.gz
Algorithm Hash digest
SHA256 cb2c19cea7b42f28901129ca6e09b5637f63ff46332222418174d8cd711ed5d3
MD5 a38bfecb6366921c1f90a3dc097ae09e
BLAKE2b-256 b99cf3ccc14b88bbadb8b65711a46f5fa35a5eef8b8a2583a69b8e4fe32076dc

See more details on using hashes here.

File details

Details for the file blist-0.9.4-py2.5-win32.egg.

File metadata

File hashes

Hashes for blist-0.9.4-py2.5-win32.egg
Algorithm Hash digest
SHA256 0f2f9660ef61f5d3b437eb9c60891d887c7cba516551dbf8fe787875b0d35b94
MD5 9ee2e443a559cc12677c8fbda72d1119
BLAKE2b-256 da26f4f21418fc9966af88ac30ac2fa90063e64d7a201412a0774a5b95484694

See more details on using hashes here.

File details

Details for the file blist-0.9.4-py2.5-linux-i686.egg.

File metadata

File hashes

Hashes for blist-0.9.4-py2.5-linux-i686.egg
Algorithm Hash digest
SHA256 db6fd3acee22e5efc3e353e69bd8f40c63aca300c639855eb438f6f5accc24f5
MD5 7b68e727f27bf339ca9b888440d59118
BLAKE2b-256 d233ac3e2df693a3b6c1fe25d44acd71c766b356ac8a71b62b2c5664116442a6

See more details on using hashes here.

File details

Details for the file blist-0.9.4-py2.5-cygwin-1.5.23-i686.egg.

File metadata

File hashes

Hashes for blist-0.9.4-py2.5-cygwin-1.5.23-i686.egg
Algorithm Hash digest
SHA256 5499692b6cb4a5bb9d79a21a62dcabefe0e9ecb1d0f38a0de3a93e5e75781b72
MD5 22777bfa720034b890406dddb5b20b42
BLAKE2b-256 dda7ebe6a0ff14f6233577a1333d2af4768ce77cb873f4110c753e4510ad0664

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page