Structures
LiFoStack
Last-In-First-Out (LIFO) stack implementation using linked nodes.
A stack data structure that follows the LIFO principle where elements are added and removed from the same end.
Attributes:
Name | Type | Description |
---|---|---|
_tail |
Node
|
The tail node of the stack. |
_cursor |
Node
|
Current position for iteration. |
_len |
int
|
Number of elements in the stack. |
Methods:
Name | Description |
---|---|
push |
Pushes an element onto the top of the stack. |
get |
Returns but does not remove the top element. |
pop |
Removes and returns the top element. |
is_head |
Checks if the stack is at the head position. |
Source code in apps/annotator/code/utils/structures.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
get(indx=None, raise_exception=False)
Returns but does not remove the top element of the stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indx
|
int
|
Currently unused parameter. |
None
|
raise_exception
|
bool
|
If True, raises an exception when stack is empty. |
False
|
Returns:
Type | Description |
---|---|
any or None
|
The top element of the stack, or None if stack is empty and raise_exception is False. |
Raises:
Type | Description |
---|---|
Exception
|
If the stack is empty and raise_exception is True. |
Source code in apps/annotator/code/utils/structures.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
pop(raise_exception=False)
Removes and returns the top element of the stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raise_exception
|
bool
|
If True, raises an exception when stack is empty. |
False
|
Returns:
Type | Description |
---|---|
any or None
|
The top element of the stack, or None if stack is empty and raise_exception is False. |
Source code in apps/annotator/code/utils/structures.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
push(elem)
Pushes an element onto the top of the stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elem
|
any
|
The element to be pushed onto the stack. |
required |
Source code in apps/annotator/code/utils/structures.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
Node
A node class for implementing linked data structures.
Attributes:
Name | Type | Description |
---|---|---|
value |
any
|
The value stored in the node. |
_prev |
Node or None
|
Reference to the previous node in the structure. |
Methods:
Name | Description |
---|---|
set_prev |
Sets the previous node reference and returns self. |
get_prev |
Returns the previous node reference. |
Source code in apps/annotator/code/utils/structures.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|