Class Lifo
source code
This class can be used to build LIFO buffers, also commonly known as
"stacks". Lifo allows you to store and retrieve Python
objects from its stack, in a very smart way. This implementation is much
faster than the one provided by Python (queue module) and more
sofisticated.
Sample code:
>>>
>>> from entropy.misc import Lifo
>>> stack = Lifo()
>>> item1 = set([1,2,3])
>>> item2 = ["a","b", "c"]
>>> item3 = None
>>> item4 = 1
>>> stack.push(item4)
>>> stack.push(item3)
>>> stack.push(item2)
>>> stack.push(item1)
>>> stack.is_filled()
True
# discarding all the item matching int(1) in the stack
>>> stack.discard(1)
>>> item3 is stack.pop()
True
>>> item2 is stack.pop()
True
>>> item1 is stack.pop()
True
>>> stack.pop()
ValueError exception (stack is empty)
>>> stack.is_filled()
False
>>> del stack
|
|
|
|
None
|
|
|
None
|
|
|
bool
|
|
|
None
|
|
|
any Python object
|
|
|
Push an object into the stack.
- Parameters:
item (Python object) - any Python object
- Returns: None
- None
|
|
Clear the stack.
- Returns: None
- None
|
|
Tell whether Lifo contains data that can be popped out.
- Returns: bool
- fill status
|
|
Remove given object from stack. Any matching object, through identity
and == comparison will be removed.
- Parameters:
entry (any Python object) - object in stack
- Returns: None
- None
|
|
Pop the uppermost item of the stack out of it.
- Returns: any Python object
- object stored in the stack
- Raises:
ValueError - if stack is empty
|