eta.util.buffer
Utilities for manipulating priority queues, termed “buffers” in Eta’s architecture.
NOTE: although importance values are positive, the values stored in the underlying priority queues are negated, since heapq implements a min heap.
Functions
Empty a buffer. |
|
Enqueue an item (either an object or an (importance, object) tuple) in a buffer. |
|
Enqueue a list of items, preserving original order unless an importance value is explicitly specified. |
|
Get the top item from a buffer without popping it. |
|
Check whether a buffer is empty. |
|
Return a buffer as a list (optionally applying some function to each value). |
|
Get the maximum importance value from a buffer. |
|
Pop all items from a buffer. |
|
Pop the top item from a buffer. |
- enqueue(item, buffer)[source]
Enqueue an item (either an object or an (importance, object) tuple) in a buffer.
- enqueue_ordered(items, buffer, inc_val=0.0001)[source]
Enqueue a list of items, preserving original order unless an importance value is explicitly specified.
- Parameters:
items (list) – A list where each item is either an object or (importance, object) tuple. For each item where an importance is not specified, a default importance value is generated using an increment so as to preserve the original order.
inc_val (float, default=0.0001) – The increment to use for generated importance values.