Helper functions for manipulating singly-linked lists.
- See also
- list.h, util::List.
This class defines a set of template functions for manipulating singly-linked lists. They are packaged into a single class to make it easier to "friend" the entire group.
Most users should instantiate and use the util::List class, rather than calling these functions directly. The base class is provided for edge-cases that must use bare pointers, such as the global linked lists used in "polling.h".
Definition at line 52 of file list.h.
|
|
template<class T > |
| static void | add (T *&list, T *item) |
| | Add new item to front or back, whichever is simpler.
|
| |
| template<class T > |
| static void | add_list (T *&list1, T *&list2) |
| | Add each item from "list2" onto "list1", destroying "list2". More...
|
| |
| template<class T > |
| static void | add_safe (T *&list, T *item) |
| | Check if list already contains item before adding. More...
|
| |
|
template<class T > |
| static bool | contains (const T *list, const T *item) |
| | Scan the list, looking for the item in question.
|
| |
| template<class T > |
| static T ** | find_ptr (T **list, const T *item) |
| | Find the link pointing to the designated item. More...
|
| |
| template<class T > |
| static T * | get_index (T *list, unsigned idx) |
| | Fetch the Nth item from the linked list. More...
|
| |
|
template<class T > |
| static bool | has_loop (const T *list) |
| | Check if the linked list loops back on itself, using the two-pointer "tortoise and hare" algorithm.
|
| |
|
template<class T > |
| static void | insert_after (T *where, T *item) |
| | Insert a new item just after the designated position.
|
| |
|
template<class T > |
| static unsigned | len (const T *list) |
| | Traverse the linked list to count its length.
|
| |
| template<class T > |
| static T * | next (const T *item) |
| | Fetch pointer to the next item. More...
|
| |
|
template<class T > |
| static T * | pop_front (T *&list) |
| | Remove the item at the head of the list.
|
| |
|
template<class T > |
| static void | push_front (T *&list, T *item) |
| | Add a new item at the head of the list.
|
| |
|
template<class T > |
| static void | push_back (T *&list, T *item) |
| | Add a new item at the tail of the list.
|
| |
|
template<class T > |
| static void | remove (T *&list, T *item) |
| | Remove the designated item from the list.
|
| |
|
template<class T > |
| static void | reset (T *&list, T *item) |
| | Discard list contents and reset to empty or a single item.
|
| |
| template<class T > |
| static bool | pre_test_reset (T *&list, T *item) |
| | Check if a list contains exactly the specified item. More...
|
| |