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()to:
>>> 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 operations. Creating a btuple from any other iterable requires operations.
Returns a new btuple by concatenating two tuples.
If the other tuple is also a btuple, requires operations. If it’s a built-in tuple, requires operations, where m is the size of the other tuple and n is the size of L.
Return type: | btuple |
---|
Returns True if and only if x is an element in the tuple.
Requires operations in the worst case.
Return type: | bool |
---|
Compares two tuples. For full details see Comparisons in the Python language reference.
Requires operations in the worst case.
Return type: | bool |
---|
Returns the element at position i.
Requires operations in the amortized worst case.
Return type: | item |
---|
Returns a new btuple containing the elements from i to j.
Requires operations.
Return type: | btuple |
---|
Creates an iterator over the tuple.
Requires operations to create the iterator. Each element from the iterator requires operations to retrieve, or operations to iterate over the entire tuple.
Return type: | iterator |
---|
Returns the number of occurrences of value in the tuple.
Requires operations in the worst case.
Return type: | int |
---|
Returns the smallest k such that and . 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 operations in the worst case.
Return type: | int |
---|