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

Uploaded Source

Built Distributions

blist-0.9.12.win32-py3.0.exe (222.5 kB view details)

Uploaded Source

blist-0.9.12.win32-py2.6.exe (93.6 kB view details)

Uploaded Source

blist-0.9.12-py2.6-linux-i686.egg (87.3 kB view details)

Uploaded Egg

blist-0.9.12-py2.5-linux-i686.egg (87.2 kB view details)

Uploaded Egg

blist-0.9.12-py2.5-cygwin-1.5.25-i686.egg (90.5 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for blist-0.9.12.tar.gz
Algorithm Hash digest
SHA256 861cbf4995dd19a0f6dccd43f14480855e932b52df8c056a831f528dace2a5ce
MD5 d25928aeacee829fdca35bfdc20a575f
BLAKE2b-256 63c4410879988b754a0cb7f749b0f1280636decfd9d2b07c08d128054e0d9f0e

See more details on using hashes here.

File details

Details for the file blist-0.9.12.win32-py3.0.exe.

File metadata

File hashes

Hashes for blist-0.9.12.win32-py3.0.exe
Algorithm Hash digest
SHA256 e11f07d55163c79b5bef1245067dcdaadc964768cc10d56b5f1d78cb64f88f62
MD5 84de4e053daa01911a66161de8a8bf33
BLAKE2b-256 ed9403069edfb3ab5a1d75b44790e303e1622336b568a3243d1d380252440bd6

See more details on using hashes here.

File details

Details for the file blist-0.9.12.win32-py2.6.exe.

File metadata

File hashes

Hashes for blist-0.9.12.win32-py2.6.exe
Algorithm Hash digest
SHA256 b2686b86bac7a7a57362acf5602872faf625984aff4d4efcbef2701303b8465f
MD5 174c0c7857183ebaf4e6052f98ad1378
BLAKE2b-256 b0b7c9a36683b085c9671d98fa542589cc9d34282f5d13f7e1aa03060ba46e95

See more details on using hashes here.

File details

Details for the file blist-0.9.12-py2.6-linux-i686.egg.

File metadata

File hashes

Hashes for blist-0.9.12-py2.6-linux-i686.egg
Algorithm Hash digest
SHA256 bc2235fc4bb0b44c3237a2762fb05ce80b369e8d4ff18f39922218d79830aaa4
MD5 66180a0faf5ded16b21b93f78cb8cd10
BLAKE2b-256 3231c02558bf01c8a8e7aa4dbc57ea3192ef1fff702930186da3ef4967c2c544

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blist-0.9.12-py2.5-linux-i686.egg
Algorithm Hash digest
SHA256 6ae8d17140d8c777e8dc686270ab5e8ad1d84868ca1d07fe8bb8c9edf20b43d7
MD5 e96882c98f9cc7f93916976eb5da0666
BLAKE2b-256 4279a2af38e91cdd4d1f29bbc675f42cb6264542b1dc75b7c02e00445999aaaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blist-0.9.12-py2.5-cygwin-1.5.25-i686.egg
Algorithm Hash digest
SHA256 2ff678654cfab9880c34d019ef61df529f0f3205b08e7b482598fe75c2641026
MD5 9224878c663dd1df6f0fe39fe47998a2
BLAKE2b-256 dce40e3227685ddb2fb068e33a2d50a1a7cebd29eb238a7a191ed658d00a0249

See more details on using hashes here.

Supported by

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