The multilist, representing an abstract data type that generally holds lists. More...
#include <DS_Multilist.h>
Public Member Functions | |
Multilist () | |
~Multilist () | |
Multilist (const Multilist &source) | |
Multilist & | operator= (const Multilist &source) |
_DataType & | operator[] (const _IndexType position) const |
void | Push (const _DataType &d, const char *file=__FILE__, unsigned int line=__LINE__) |
void | Push (const _DataType &d, const _KeyType &key, const char *file=__FILE__, unsigned int line=__LINE__) |
_DataType & | Pop (const char *file=__FILE__, unsigned int line=__LINE__) |
Gets or removes and gets an element from the list, according to the same rules as Push(). Ordered list is LIFO for the purposes of Pop and Peek. | |
_DataType & | Peek (void) const |
void | PushOpposite (const _DataType &d, const char *file=__FILE__, unsigned int line=__LINE__) |
Same as Push(), except FIFO and LIFO are reversed. Ordered list still inserts in order. | |
void | PushOpposite (const _DataType &d, const _KeyType &key, const char *file=__FILE__, unsigned int line=__LINE__) |
_DataType & | PopOpposite (const char *file=__FILE__, unsigned int line=__LINE__) |
Same as Pop() and Peek(), except FIFO and LIFO are reversed. | |
_DataType & | PeekOpposite (void) const |
void | InsertAtIndex (const _DataType &d, _IndexType index, const char *file=__FILE__, unsigned int line=__LINE__) |
Stack,Queue: Inserts at index indicated, elements are shifted. Ordered list: Inserts, position is ignored. | |
void | RemoveAtIndex (_IndexType position, const char *file=__FILE__, unsigned int line=__LINE__) |
Unordered list, removes at index indicated, swaps last element with that element. Otherwise, array is shifted left to overwrite removed element. | |
bool | RemoveAtKey (_KeyType key, bool assertIfDoesNotExist, const char *file=__FILE__, unsigned int line=__LINE__) |
Find the index of key, and remove at that index. | |
_IndexType | GetIndexOf (_KeyType key) const |
Finds the index of key. Return -1 if the key is not found. | |
_IndexType | GetInsertionIndex (_KeyType key) const |
Returns where in the list we should insert the item, to preserve list order. Returns -1 if the item is already in the list. | |
_DataType | GetPtr (_KeyType key) const |
Finds the index of key. Return 0 if the key is not found. Useful if _DataType is always non-zero pointers. | |
void | ForEach (void(*func)(_DataType &item, const char *file, unsigned int line), const char *file, unsigned int line) |
Iterate over the list, calling the function pointer on each element. | |
void | ForEach (void(*func)(_DataType &item)) |
bool | IsEmpty (void) const |
Returns if the list is empty. | |
_IndexType | GetSize (void) const |
Returns the number of elements used in the list. | |
void | Clear (bool deallocateSmallBlocks=true, const char *file=__FILE__, unsigned int line=__LINE__) |
Empties the list. The list is not deallocated if it is small, unless deallocateSmallBlocks is true. | |
void | ClearPointers (bool deallocateSmallBlocks=true, const char *file=__FILE__, unsigned int line=__LINE__) |
Empties the list, first calling RakNet::OP_Delete on all items. | |
void | ClearPointer (_KeyType key, const char *file=__FILE__, unsigned int line=__LINE__) |
Empty one item from the list, first calling RakNet::OP_Delete on that item. | |
void | ReverseList (void) |
Reverses the elements in the list, and flips the sort order returned by GetSortOrder() if IsSorted() returns true at the time the function is called. | |
void | Reallocate (_IndexType size, const char *file=__FILE__, unsigned int line=__LINE__) |
Reallocates the list to a larger size. If size is smaller than the value returned by GetSize(), the call does nothing. | |
void | Sort (bool force) |
Sorts the list unless it is an ordered list, in which it does nothing as the list is assumed to already be sorted. | |
void | TagSorted (void) |
Sets the list to be remembered as sorted. | |
void | SetSortOrder (bool ascending) |
Defaults to ascending. | |
bool | GetSortOrder (void) const |
Returns true if ascending. | |
bool | IsSorted (void) const |
Returns true if the list is currently believed to be in a sorted state. | |
MultilistType | GetMultilistType (void) const |
Returns what type of list this is. | |
void | SetMultilistType (MultilistType newType) |
Changes what type of list this is. | |
Static Public Member Functions | |
static void | FindIntersection (Multilist &source1, Multilist &source2, Multilist &intersection, Multilist &uniqueToSource1, Multilist &uniqueToSource2) |
Returns the intersection of two lists. Intersection is items common to both lists. | |
Protected Types | |
enum | { ML_UNSORTED, ML_SORTED_ASCENDING, ML_SORTED_DESCENDING } |
Protected Member Functions | |
void | ReallocateIfNeeded (const char *file, unsigned int line) |
void | DeallocateIfNeeded (const char *file, unsigned int line) |
void | ReallocToSize (_IndexType newAllocationSize, const char *file, unsigned int line) |
void | ReverseListInternal (void) |
void | InsertInOrderedList (const _DataType &d, const _KeyType &key) |
_IndexType | GetIndexFromKeyInSortedList (const _KeyType &key, bool *objectExists) const |
void | InsertShiftArrayRight (const _DataType &d, _IndexType index) |
void | DeleteShiftArrayLeft (_IndexType index) |
void | QSortAscending (_IndexType left, _IndexType right) |
void | QSortDescending (_IndexType left, _IndexType right) |
void | CopySource (const Multilist &source) |
Protected Attributes | |
_DataType * | data |
An array of user values. | |
_IndexType | dataSize |
Number of elements in the list. | |
_IndexType | allocationSize |
Size of array. | |
_IndexType | queueHead |
Array index for the head of the queue. | |
_IndexType | queueTail |
Array index for the tail of the queue. | |
_IndexType | preallocationSize |
enum DataStructures::Multilist:: { ... } | sortState |
bool | ascendingSort |
MultilistType | variableMultilistType |
The multilist, representing an abstract data type that generally holds lists.
[in] | _MultilistType | What type of list this is, |
[in] | _DataType | What type of data this list holds. |
[in] | _KeyType | If a function takes a key to sort on, what type of key this is. The comparison operator between _DataType and _KeyType must be defined |
[in] | _IndexType | What variable type to use for indices |
Definition at line 91 of file DS_Multilist.h.
anonymous enum [protected] |
Definition at line 241 of file DS_Multilist.h.
DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Multilist | ( | ) |
Definition at line 255 of file DS_Multilist.h.
DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::~Multilist | ( | ) |
DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Multilist | ( | const Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | source | ) |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Clear | ( | bool | deallocateSmallBlocks = true , |
|
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Empties the list. The list is not deallocated if it is small, unless deallocateSmallBlocks is true.
Definition at line 773 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ClearPointer | ( | _KeyType | key, | |
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Empty one item from the list, first calling RakNet::OP_Delete on that item.
Definition at line 804 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ClearPointers | ( | bool | deallocateSmallBlocks = true , |
|
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Empties the list, first calling RakNet::OP_Delete on all items.
The list is not deallocated if it is small, unless deallocateSmallBlocks is true
Definition at line 795 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::CopySource | ( | const Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | source | ) | [protected] |
Definition at line 297 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::DeallocateIfNeeded | ( | const char * | file, | |
unsigned int | line | |||
) | [protected] |
Definition at line 1158 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::DeleteShiftArrayLeft | ( | _IndexType | index | ) | [protected] |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::FindIntersection | ( | Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | source1, | |
Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | source2, | |||
Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | intersection, | |||
Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | uniqueToSource1, | |||
Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | uniqueToSource2 | |||
) | [static] |
Returns the intersection of two lists. Intersection is items common to both lists.
Definition at line 1088 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ForEach | ( | void(*)(_DataType &item, const char *file, unsigned int line) | func, | |
const char * | file, | |||
unsigned int | line | |||
) |
Iterate over the list, calling the function pointer on each element.
Definition at line 745 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ForEach | ( | void(*)(_DataType &item) | func | ) |
Definition at line 753 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetIndexFromKeyInSortedList | ( | const _KeyType & | key, | |
bool * | objectExists | |||
) | const [protected] |
Definition at line 1235 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetIndexOf | ( | _KeyType | key | ) | const |
Finds the index of key. Return -1 if the key is not found.
Definition at line 668 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetInsertionIndex | ( | _KeyType | key | ) | const |
Returns where in the list we should insert the item, to preserve list order. Returns -1 if the item is already in the list.
Definition at line 702 of file DS_Multilist.h.
MultilistType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetMultilistType | ( | void | ) | const |
Returns what type of list this is.
Definition at line 984 of file DS_Multilist.h.
_DataType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetPtr | ( | _KeyType | key | ) | const |
Finds the index of key. Return 0 if the key is not found. Useful if _DataType is always non-zero pointers.
Definition at line 736 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetSize | ( | void | ) | const |
Returns the number of elements used in the list.
Definition at line 767 of file DS_Multilist.h.
bool DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::GetSortOrder | ( | void | ) | const |
Returns true if ascending.
Definition at line 972 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::InsertAtIndex | ( | const _DataType & | d, | |
_IndexType | index, | |||
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Stack,Queue: Inserts at index indicated, elements are shifted. Ordered list: Inserts, position is ignored.
Definition at line 534 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::InsertInOrderedList | ( | const _DataType & | d, | |
const _KeyType & | key | |||
) | [protected] |
Definition at line 1206 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::InsertShiftArrayRight | ( | const _DataType & | d, | |
_IndexType | index | |||
) | [protected] |
bool DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::IsEmpty | ( | void | ) | const |
Returns if the list is empty.
Definition at line 761 of file DS_Multilist.h.
bool DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::IsSorted | ( | void | ) | const |
Returns true if the list is currently believed to be in a sorted state.
Doesn't actually check for sortedness, just if Sort() was recently called, or MultilistType is ML_ORDERED_LIST
Definition at line 978 of file DS_Multilist.h.
Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::operator= | ( | const Multilist< _MultilistType, _DataType, _KeyType, _IndexType > & | source | ) |
_DataType & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::operator[] | ( | const _IndexType | position | ) | const |
Definition at line 322 of file DS_Multilist.h.
_DataType & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Peek | ( | void | ) | const |
_DataType & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::PeekOpposite | ( | void | ) | const |
_DataType & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Pop | ( | const char * | file = __FILE__ , |
|
unsigned int | line = __LINE__ | |||
) |
Gets or removes and gets an element from the list, according to the same rules as Push(). Ordered list is LIFO for the purposes of Pop and Peek.
Definition at line 389 of file DS_Multilist.h.
_DataType & DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::PopOpposite | ( | const char * | file = __FILE__ , |
|
unsigned int | line = __LINE__ | |||
) |
Same as Pop() and Peek(), except FIFO and LIFO are reversed.
Definition at line 481 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Push | ( | const _DataType & | d, | |
const _KeyType & | key, | |||
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Push | ( | const _DataType & | d, | |
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Unordered list, stack is LIFO QUEUE is FIFO Ordered list is inserted in order
Definition at line 338 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::PushOpposite | ( | const _DataType & | d, | |
const _KeyType & | key, | |||
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::PushOpposite | ( | const _DataType & | d, | |
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Same as Push(), except FIFO and LIFO are reversed. Ordered list still inserts in order.
Definition at line 429 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::QSortAscending | ( | _IndexType | left, | |
_IndexType | right | |||
) | [protected] |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::QSortDescending | ( | _IndexType | left, | |
_IndexType | right | |||
) | [protected] |
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Reallocate | ( | _IndexType | size, | |
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Reallocates the list to a larger size. If size is smaller than the value returned by GetSize(), the call does nothing.
Definition at line 825 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ReallocateIfNeeded | ( | const char * | file, | |
unsigned int | line | |||
) | [protected] |
Definition at line 1136 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ReallocToSize | ( | _IndexType | newAllocationSize, | |
const char * | file, | |||
unsigned int | line | |||
) | [protected] |
Definition at line 1173 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::RemoveAtIndex | ( | _IndexType | position, | |
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Unordered list, removes at index indicated, swaps last element with that element. Otherwise, array is shifted left to overwrite removed element.
Index[0] returns the same as Pop() for a queue. Same as PopOpposite() for the list and ordered list
Definition at line 601 of file DS_Multilist.h.
bool DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::RemoveAtKey | ( | _KeyType | key, | |
bool | assertIfDoesNotExist, | |||
const char * | file = __FILE__ , |
|||
unsigned int | line = __LINE__ | |||
) |
Find the index of key, and remove at that index.
Definition at line 655 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ReverseList | ( | void | ) |
Reverses the elements in the list, and flips the sort order returned by GetSortOrder() if IsSorted() returns true at the time the function is called.
Definition at line 816 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ReverseListInternal | ( | void | ) | [protected] |
Definition at line 1193 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::SetMultilistType | ( | MultilistType | newType | ) |
Changes what type of list this is.
[in] | mlType | Any value of the enum MultilistType, except ML_VARIABLE_DURING_RUNTIME |
Definition at line 992 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::SetSortOrder | ( | bool | ascending | ) |
Defaults to ascending.
Used by Sort(), and by ML_ORDERED_LIST
Definition at line 959 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::Sort | ( | bool | force | ) |
Sorts the list unless it is an ordered list, in which it does nothing as the list is assumed to already be sorted.
However, if force is true, it will also resort the ordered list, useful if the comparison operator between _KeyType and _DataType would now return different results Once the list is sorted, further operations to lookup by key will be log2(n) until the list is modified
Definition at line 837 of file DS_Multilist.h.
void DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::TagSorted | ( | void | ) |
Sets the list to be remembered as sorted.
Optimization if the source is sorted already
Definition at line 854 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::allocationSize [protected] |
Size of array.
Definition at line 229 of file DS_Multilist.h.
bool DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::ascendingSort [protected] |
Definition at line 248 of file DS_Multilist.h.
_DataType* DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::data [protected] |
An array of user values.
Definition at line 223 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::dataSize [protected] |
Number of elements in the list.
Definition at line 226 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::preallocationSize [protected] |
How many bytes the user chose to preallocate Won't automatically deallocate below this
Definition at line 239 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::queueHead [protected] |
Array index for the head of the queue.
Definition at line 232 of file DS_Multilist.h.
_IndexType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::queueTail [protected] |
Array index for the tail of the queue.
Definition at line 235 of file DS_Multilist.h.
enum { ... } DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::sortState [protected] |
MultilistType DataStructures::Multilist< _MultilistType, _DataType, _KeyType, _IndexType >::variableMultilistType [protected] |
Definition at line 251 of file DS_Multilist.h.