Class List
Data structure that allows for fast removal at the cost of containing order.
Methods
List:new () | Creates a new List. |
List:add (obj) | Adds an object to the List. |
List:remove (obj) | Removes an object from the List. |
List:clear () | Clears the List completely. |
List:has (obj) | Returns true if the List has the object. |
List:get (i) | Returns the object at an index. |
List:indexOf (obj) | Returns the index of an object in the List. |
List:sort (order) | Sorts the List in place, using the order function. |
List:onAdded (obj) | Callback for when an item is added to the List. |
List:onRemoved (obj) | Callback for when an item is removed to the List. |
Methods
- List:new ()
-
Creates a new List.
Returns:
-
List
A new List
- List:add (obj)
-
Adds an object to the List.
Object must be of reference type
Object may not be the string 'size', 'onAdded' or 'onRemoved'
Parameters:
- obj Object to add
Returns:
-
List
self
- List:remove (obj)
-
Removes an object from the List.
Parameters:
- obj Object to remove
Returns:
-
List
self
- List:clear ()
-
Clears the List completely.
Returns:
-
List
self
- List:has (obj)
-
Returns true if the List has the object.
Parameters:
- obj Object to check for
Returns:
-
boolean
- List:get (i)
-
Returns the object at an index.
Parameters:
- i number Index to get from
Returns:
-
Object at the index
- List:indexOf (obj)
-
Returns the index of an object in the List.
Parameters:
- obj Object to get index of
Returns:
-
number
index of object in the List.
- List:sort (order)
-
Sorts the List in place, using the order function.
The order function is passed to table.sort internally so documentation on table.sort can be used as reference.
Parameters:
- order Function that takes two Entities (a and b) and returns true if a should go before than b.
Returns:
-
List
self
- List:onAdded (obj)
-
Callback for when an item is added to the List.
Parameters:
- obj Object that was added
- List:onRemoved (obj)
-
Callback for when an item is removed to the List.
Parameters:
- obj Object that was removed