-
-
Notifications
You must be signed in to change notification settings - Fork 0
StackableList
Namespace: Lowry.Utils.CodeExtensions
public sealed class StackableList<T> : List<T>
Stores a "stack" of unique items.
Using Push will add/move an item to the top of the list Top.
Using Pop will remove an item from the list and return it.
This class functions as a hybrid between a List🔗 and a Stack🔗, offering the possibility of pushing (stacking) unique items from a list, and then popping them (pulling them out).
Upon popping, a StackableListPopResults is returned to indicate whether the item was:
- Removed from the top, and the top spot taken by another item.
- Removed from the top, but the list is now empty.
- Removed from anywhere but the top of the list.
- Not found in the list.
public enum PopResult
{
notFound,
removedFromTop_Replaced,
removedFromTop_Empty,
removed
}
public T Top {get {...} }
Returns: the item currently at the top of the stack.
public T Push (T item) {...}
Try to add a new item to the top of the stack, or move an already present item to the top.
Returns:
- If
default
(usuallynull
): The item was added to an empty list.- If same as input: The item was already at the top if the stack.
- If other item of type
T
: The item was added to the top of the stack;
This returned item was previously at the top of the stack.
public StackableListPopResults<T> Pop (T item) {...}
Try to remove an item from the stack.
Returns: A StackableListPopResults containing an item of type
T
and a PopResult that indicates the result of the action.
👉🏻 Download InputLayers on the Unity Asset Store!