Minimal stack that uses a pool to avoid pointers. More...
#include <smallstack_type.hpp>
Data Structures | |
class | PooledSmallStack |
SmallStack item that can be kept in a pool (by having an index). More... | |
Public Types | |
typedef SmallStackItem< Tindex, Titem > | Item |
typedef Pool< PooledSmallStack, Tindex, Tgrowth_step, Tmax_size, PT_NORMAL, true, false > | SmallStackPool |
Public Member Functions | |
SmallStack (const Titem &value=Tinvalid) | |
Constructor for a stack with one or two items in it. | |
~SmallStack () | |
Remove the head of stack and all other items members that are unique to it. | |
SmallStack (const SmallStack &other) | |
Shallow copy the stack, marking the first item as branched. | |
SmallStack & | operator= (const SmallStack &other) |
Shallow copy the stack, marking the first item as branched. | |
void | Push (const Titem &item) |
Push a new item onto the stack. | |
Titem | Pop () |
Pop an item from the stack. | |
bool | IsEmpty () const |
Check if the stack is empty. | |
bool | Contains (const Titem &item) const |
Check if the given item is contained in the stack. | |
Protected Member Functions | |
void | Branch () |
Create a branch in the pool if necessary. | |
Static Protected Attributes | |
static SmallStackPool | _pool |
Minimal stack that uses a pool to avoid pointers.
It has some peculiar properties that make it useful for passing around lists of IDs but not much else: 1. It always includes an invalid item as bottom. 2. It doesn't have a deep copy operation but uses smart pointers instead. Every copy is thus implicitly shared. 3. Its items are immutable. 4. Due to 2. and 3. memory management can be done by "branch counting". Whenever you copy a smallstack, the first item on the heap increases its branch_count, signifying that there are multiple items "in front" of it. When deleting a stack items are deleted up to the point where branch_count > 0. 5. You can choose your own index type, so that you can align it with your value type. E.G. value types of 16 bits length like to be combined with index types of the same length.
Titem | Value type to be used. | |
Tindex | Index type to use for the pool. | |
Tinvalid | Invalid item to keep at the bottom of each stack. | |
Tgrowth_step | Growth step for pool. | |
Tmax_size | Maximum size for pool. |
Definition at line 60 of file smallstack_type.hpp.
SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::SmallStack | ( | const Titem & | value = Tinvalid |
) | [inline] |
Constructor for a stack with one or two items in it.
value | Initial item. If not missing or Tinvalid there will be Tinvalid below it. |
Definition at line 82 of file smallstack_type.hpp.
SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::SmallStack | ( | const SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size > & | other | ) | [inline] |
Shallow copy the stack, marking the first item as branched.
other | Stack to copy from |
Definition at line 103 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch().
bool SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Contains | ( | const Titem & | item | ) | const [inline] |
Check if the given item is contained in the stack.
item | Item to look for. |
Definition at line 170 of file smallstack_type.hpp.
References SmallStackItem< Tindex, Titem >::next, and SmallStackItem< Tindex, Titem >::value.
Referenced by VehicleCargoList::ChooseAction().
bool SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty | ( | ) | const [inline] |
Check if the stack is empty.
Definition at line 160 of file smallstack_type.hpp.
References SmallStackItem< Tindex, Titem >::next, and SmallStackItem< Tindex, Titem >::value.
Referenced by OrderList::GetNextStoppingStation(), StationCargoList::HasCargoFor(), StationCargoList::ShiftCargo(), VehicleCargoList::Stage(), and LinkGraphJob::~LinkGraphJob().
SmallStack& SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::operator= | ( | const SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size > & | other | ) | [inline] |
Shallow copy the stack, marking the first item as branched.
other | Stack to copy from |
Definition at line 110 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch(), SmallStackItem< Tindex, Titem >::next, SmallStackItem< Tindex, Titem >::value, and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::~SmallStack().
Titem SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop | ( | ) | [inline] |
Pop an item from the stack.
Definition at line 138 of file smallstack_type.hpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch(), SmallStackItem< Tindex, Titem >::next, and SmallStackItem< Tindex, Titem >::value.
Referenced by OrderList::GetNextStoppingStation(), StationCargoList::HasCargoFor(), StationCargoList::ShiftCargo(), VehicleCargoList::Stage(), and LinkGraphJob::~LinkGraphJob().
void SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Push | ( | const Titem & | item | ) | [inline] |
Push a new item onto the stack.
item | Item to be pushed. |
Definition at line 124 of file smallstack_type.hpp.
References SmallStackItem< Tindex, Titem >::next, and SmallStackItem< Tindex, Titem >::value.
Referenced by FlowStatMap::DeleteFlows(), and OrderList::GetNextStoppingStation().