utimeq – heap queue with times¶
Difference to CPython
This is a MicroPython specific module. It’s based on heapq but
its implementation is more specialized than that, and it’s not possible to
use list operations like indexing on it.
This module uses the heap queue algorithm (priority queue algorithm) to create a heap queue where entries are popped based on which has the earliest time.
Classes¶
- class utimeq.utimeq(n)¶
Create a utimeq heap queue with space for n entries. This size is static, and an attempt to push too many entries onto it will throw an IndexError with message ‘queue overflow’.
The queue sorts itself by entries’
timeparameters, and then by the order in which entries were pushed for entries with equal times. So entries with lowertimeparameters get popped first, and for entries with the sametimethe first only that was pushed gets popped first.The heap queue can be tested for non-emptiness with “if(heap)”.
- push(time, obj, userdata)¶
Push an entry onto the heap queue.
The
timeparameter should be a number of ticks (see the utime module) compatible withutime.ticks_diff().The
objanduserdataparameters are not used internally, so the user can set them to anything. (The underlying MicroPython code suggests a callback and its arguments.)