Classes | |
class | ListItem |
Embedded Doubly-Linked-List Class. More... | |
class | ListMergeSort |
Merge-sort functor for ListItem lists. More... | |
class | ListRadixSort |
Radix-sort functor for ListItem lists. More... | |
class | SListItem |
Embedded Singly-linked list Class. More... | |
class | SListQueue |
Queue head for SListItem elements supporting FIFO operations. More... | |
class | SListRadixSort |
Radix-sort functor for SListItem lists. More... | |
Defines | |
#define | GetContainer(memberptr, type, member) static_cast<type*>(__GetContainer(memberptr, &type::member)) |
Get a pointer to a structure containing a given ListItem. | |
#define | ListForEach(listp, head) for (listp = (head)->next; listp != (head); listp = listp->next) |
Forward list iterator. | |
#define | ListForEachReverse(listp, head) for (listp = (head)->prev; listp != (head); listp = listp->prev) |
Reverse list iterator. |
First, the ListItem object, a doubly-linked list, supports unrestricted O(1) insertions and removals. Very simple and versatile.
Second, the SListItem object, a singly-linked list, supports strict LIFO operations, where only succeeding elements can be removed. SListItem is less applicable than ListItem, but requires less memory.
The Linked-List package also provides basic sorting algorithms, including Merge Sort and Radix Sort. These are provided in the ListMergeSort, ListRadixSort, and SListRadixSort functor classes.
If items require infrequent sorting by one of several attributes, consider using ListItem to list items, and MergeSort or RadixSort to perform the infrequent sorting. If items are frequently searched or enumerated in order, and sorted by a single attribute, consider using the BinTree class. For twice the amount of space in each item, and more expensive insertions and removals, it provides incremental sorting and bidirectional enumerability.
To use a List:
#define GetContainer | ( | memberptr, | |||
type, | |||||
member | ) | static_cast<type*>(__GetContainer(memberptr, &type::member)) |
Get a pointer to a structure containing a given ListItem.
memberptr | Pointer to the embedded ListItem. | |
type | Name of structure type containing the list. | |
member | Name of structure member of the ListItem. |
struct some_struct { int stuff. ... ListItem mylist; ... }
and have a pointer to its mylist member, and need a pointer to the struct some_struct, just use:
GetContainer(listptr, struct some_struct, mylist)
#define ListForEach | ( | listp, | |||
head | ) | for (listp = (head)->next; listp != (head); listp = listp->next) |
Forward list iterator.
For-loop iterating over all members of a list in forward order.
listp | Iterator variable, assigned to the ListItem under consideration for each iteration. | |
head | List head. Iteration starts at the beginning of this, and stops when listp == head. |
#define ListForEachReverse | ( | listp, | |||
head | ) | for (listp = (head)->prev; listp != (head); listp = listp->prev) |
Reverse list iterator.
For-loop iterating over all members of a list in forward order.
listp | Iterator variable, assigned to the ListItem under consideration for each iteration. | |
head | List head. Iteration starts at the end of this, and stops when listp == head. |