Class OptimizedActivationStack<T>
- Namespace
- Aplib.Core.Collections
- Assembly
- Aplib.Core.dll
A stack that has a predefined set of items that can be activated (i.e., pushed on top of the stack). When an item that is already on the stack is activated, it is reactivated (i.e., moved to the top of the stack).
public class OptimizedActivationStack<T>
Type Parameters
TThe type of the items that are put on the stack.
- Inheritance
-
OptimizedActivationStack<T>
- Inherited Members
Remarks
The OptimizedActivationStack<T> allows for O(1) activation and reactivation of an arbitrary stack item.
Constructors
OptimizedActivationStack(T[])
Initializes an optimized activation stack with a set of activatable data.
public OptimizedActivationStack(T[] activatables)
Parameters
activatablesT[]A set of activatable items that could be pushed on the stack.
Properties
ActivatableStackItems
Gets the activatable stack items.
public IEnumerable<OptimizedActivationStack<T>.StackItem> ActivatableStackItems { get; }
Property Value
Remarks
The stack items are exposed, since they should be accessible from the outside to provide O(1) activation of a stack item with Activate(StackItem).
Count
Gets the number of items that are currently activated (i.e., on the stack).
public int Count { get; }
Property Value
Exceptions
- InvalidOperationException
Thrown when the stack count is negative.
Methods
Activate(StackItem)
Activates an item (i.e., pushes an item on top of the stack). If the pushed item is already on the stack, it is extracted from the stack before it is put on top again.
public void Activate(OptimizedActivationStack<T>.StackItem item)
Parameters
itemOptimizedActivationStack<T>.StackItemThe stack item that is pushed on top of the stack (i.e., it is activated).
Exceptions
- ArgumentException
Thrown when an item is pushed that belongs to a different stack.
Peek()
Peeks the top item from the stack.
public T Peek()
Returns
- T
The top item.
Exceptions
- InvalidOperationException
Thrown when the stack is empty.
Pop()
Pops the top item from the stack.
public T Pop()
Returns
- T
The popped item.
Exceptions
- InvalidOperationException
Thrown when the stack is empty.