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.5.tar.gz (78.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

blist-0.9.5-py2.5-linux-i686.egg (96.2 kB view details)

Uploaded Egg

blist-0.9.5-py2.5-cygwin-1.5.25-i686.egg (80.4 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for blist-0.9.5.tar.gz
Algorithm Hash digest
SHA256 8146b3e290b1f3e0111a4c948c7b000423c51cdc46c05802a8b9b642f3aecb36
MD5 d4ba5a2c819b35c6787065de93b5712c
BLAKE2b-256 5ea2c9deeb6b8201cfb9e5a057bc103d05e75b92c5b04444c42e074d56fe0ac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blist-0.9.5-py2.5-linux-i686.egg
Algorithm Hash digest
SHA256 fbc976d5ccc3a48752a05ee99aa33c485a75ca3a876db249aff9289d67768fda
MD5 47280cd276c79831c67b30c016a83411
BLAKE2b-256 114babf4c1dac5a6538ae7de7e800f5d212739b89cbf65466f122f35a4cc3277

See more details on using hashes here.

File details

Details for the file blist-0.9.5-py2.5-cygwin-1.5.25-i686.egg.

File metadata

File hashes

Hashes for blist-0.9.5-py2.5-cygwin-1.5.25-i686.egg
Algorithm Hash digest
SHA256 c00a4789e382ce7b2995cb788590038539c92cdc9d5728062a95eb8c523f5efe
MD5 d0c6b65e0e452860776f713a60b18414
BLAKE2b-256 9fd1ca31e64e4e8913570b0847b4d842b0bf1c1e24b23d11b8b4271c59234d65

See more details on using hashes here.

Supported by

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