Skip to main content

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 lists where inserts and deletes are only at the end of the list (LIFO).

Earlier versions of BList were also slower for large lists that never change length, but this is no longer true as of version 0.9.6, which features amortized worst-case O(1) getitem and setitem operations.

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.

Metadata

Release files for blist 0.9.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blist 0.9.6
File Size Uploaded
blist-0.9.6.tar.gz 81.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blist 0.9.6
File Interpreter ABI Platform
blist-0.9.6-py2.5-linux-i686.egg Legacy Egg format - - Details

Total release size: 184.2 kB

Release files / blist-0.9.6.tar.gz

Download URL blist-0.9.6.tar.gz
Size 81.8 kB
Tags Source
SHA-256 checksum
How to use checksums
915add11cef0770043c22669f85bd63fd1ecd1fc1e2ec90acc9fab0894b144cf
BLAKE2b-256 checksum
How to use checksums
bcbc519ba2b62b9fce27bf4943a74a04fb0ab651c161d6f4d5a26a96cb04eab1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / blist-0.9.6-py2.5-linux-i686.egg

Download URL blist-0.9.6-py2.5-linux-i686.egg
Size 102.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
0f491043d7555fb2e0eac198cb9c262423dcaef7ff897cff08737daac45c832c
BLAKE2b-256 checksum
How to use checksums
c0bae8bc68b661672a8af2eddcc8e374ad5292b6cf08224979d1d367d83a83b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.3.6

1 release file

1.3.5

1 release file

1.3.4

5 release files

1.3.3

4 release files

1.3.2

1 release file

1.3.1

1 release file

1.3.0

2 release files

1.2.1

4 release files

1.2.0

4 release files

1.1.1

3 release files

1.1.0

1 release file

1.0.2

3 release files

1.0.1

8 release files

1.0.0

4 release files

0.9.17

7 release files

0.9.16

4 release files

0.9.15

7 release files

0.9.14

6 release files

0.9.13

6 release files

0.9.12

6 release files

0.9.11

3 release files

0.9.10

3 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.7

2 release files

This release

0.9.6 This release

2 release files

0.9.5

3 release files

0.9.4

4 release files

0.9.3

3 release files

0.9.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page