class blist.btuple(iterable)

The btuple is a drop-in replacement for the Python tuple that provides better performance for some operations on large tuples. Operations such as concatenation, taking a slice, and converting from a blist are inexpensive.

The current implementation of the btuple is a Python wrapper around the blist. Consequently, for small tuples the built-in tuple always provides better performance. In a future version, the btuple may be implemented in C; it would then have nearly identical performance to the built-in tuple for small tuples.

To use the btuple, you simply change code like this:

>>> items = (5, 6, 2)
>>> more_items = function_that_returns_a_tuple()


>>> from btuple import btuple
>>> items = btuple((5, 6, 2))
>>> more_items = btuple(function_that_returns_a_tuple())

Creating a btuple from another btuple or a blist requires \Theta\left(1\right) operations. Creating a btuple from any other iterable requires \Theta\left(n\right) operations.

L + L2, L2 + L

Returns a new btuple by concatenating two tuples.

If the other tuple is also a btuple, requires \Theta\left(\log m + \log n\right) operations. If it’s a built-in tuple, requires \Theta\left(m + \log n\right) operations, where m is the size of the other tuple and n is the size of L.

Return type:btuple
x in L

Returns True if and only if x is an element in the tuple.

Requires \Theta\left(n\right) operations in the worst case.

Return type:bool
L == L2, L != L2, L < L2, L <= L2, L > L2, L >= L2

Compares two tuples. For full details see Comparisons in the Python language reference.

Requires \Theta\left(n\right) operations in the worst case.

Return type:bool

Returns the element at position i.

Requires \Theta\left(1\right) operations in the amortized worst case.

Return type:item

Returns a new btuple containing the elements from i to j.

Requires \Theta\left(\log n\right) operations.

Return type:btuple

Creates an iterator over the tuple.

Requires \Theta\left(\log n\right) operations to create the iterator. Each element from the iterator requires \Theta\left(1\right) operations to retrieve, or \Theta\left(n\right) operations to iterate over the entire tuple.

Return type:iterator

Returns the number of occurrences of value in the tuple.

Requires \Theta\left(n\right) operations in the worst case.

Return type:int
L.index(value[, start[, stop]])

Returns the smallest k such that s[k] == x and i <= k < j. Raises ValueError if value is not present. stop defaults to the end of the tuple. start defaults to the beginning. Negative indexes are supported, as for slice indices.

Requires \Theta\left(\textrm{start}-\textrm{stop}\right) operations in the worst case.

Return type:int