ListItem Class Reference
[Embedded Linked List Package]

Embedded Doubly-Linked-List Class. More...

#include <list.h>

Collaboration diagram for ListItem:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ListItem (void)
 Regular Constructor.
bool Empty (void) const
 Is list empty?
void Reinitialize (void)
 Reinitialize list item.
void Unlink (void)
 Unlink and reinitialize.
void UnlinkOnly (void)
 Unlink without reinitializing.
ListItemUnlinkNext (void)
 Unlink and reinitialize successor.
ListItemUnlinkNextOnly (void)
 Unlink successor without reinitializing.
void PrependItem (ListItem &item)
 Insert a single item immediately after this element.
void AppendItem (ListItem &item)
 Insert a single item immediately before this element.
void SpliceAfter (ListItem &before_first, ListItem &last)
 Insert a sublist immediately after this element.
void SpliceBefore (ListItem &before_first, ListItem &last)
 Insert a sublist immediately before this element.
void PrependItemsFrom (ListItem &source)
 Prepends all elements of a list into this.
void AppendItemsFrom (ListItem &source)
 Appends all elements of a list into this.
int Length () const
 Compute the length of a list.
void SpliceInto (ListItem &head, ListItem &cut_start)
 Deprecated.
void SpliceIntoEnd (ListItem &head, ListItem &cut_start)
 Deprecated.

Public Attributes

ListItemnext
 List member pointer.


Detailed Description

Embedded Doubly-Linked-List Class.

ListItem is a cheap knockoff of the Linux struct list_head embeddable doubly linked list structure. It works almost identically. All methods are bonehead simple and do very little work, and are declared inline.

ListItem implements a doubly-linked-list, with O(1) insertions and removals. Very simple and versatile. Basic sorting algorithms, including MergeSort and RadixSort, are also provided through the ListMergeSort and ListRadixSort classes.

ListItem includes methods to make it useful as both an item structure and a list head structure.

Lists may also be used in a loop fashion without a start pointer, although it can be trickier.

Note:
On 32-bit platforms, a ListItem incurrs 8 bytes of overhead.

Constructor & Destructor Documentation

ListItem ( void   )  [inline]

Regular Constructor.

Initializes the list as a circular loop of one.


Member Function Documentation

bool Empty ( void   )  const [inline]

Is list empty?

Checks whether the list is an empty circular loop.

Return values:
true next points to this and prev points to this
false The list is linked with other ListItems.

void Reinitialize ( void   )  [inline]

Reinitialize list item.

Be careful with this, as it can corrupt things if the item is linked!

void Unlink ( void   )  [inline]

Unlink and reinitialize.

Unlink the ListItem from whatever list it is linked to and reinitialize it to an empty circular list.

void UnlinkOnly ( void   )  [inline]

Unlink without reinitializing.

Unlink the ListItem from whatever list it is linked to. Does not reinitialize the list. Empty() will not return the correct value. Use carefully!

ListItem* UnlinkNext ( void   )  [inline]

Unlink and reinitialize successor.

Unlink the successor element, reinitialize it, and return a pointer.

ListItem* UnlinkNextOnly ( void   )  [inline]

Unlink successor without reinitializing.

Similar to UnlinkNext(), but skips reinitializing the unlinked list.

void PrependItem ( ListItem item  )  [inline]

Insert a single item immediately after this element.

Links another ListItem to this ListItem's circular list, such that the new ListItem becomes this element's immediate successor. If this element is considered to be the head of a list, whereas item is considered to be an item, then item is prepended to the list headed by this.

Parameters:
item ListItem to be inserted.
Warning:
Blindly overwrites pointers in item. If item is linked to another list, that list will become corrupt.

void AppendItem ( ListItem item  )  [inline]

Insert a single item immediately before this element.

Links another ListItem to this ListItem's circular list, such that the new ListItem becomes this element's immediate predecessor. If this element is considered to be the head of a list, whereas item is considered to be an item, then item is appended to the list headed by this.

Parameters:
item ListItem to be inserted.
Warning:
Blindly overwrites pointers in item. If item is linked to another list, that list will become corrupt.

void SpliceAfter ( ListItem before_first,
ListItem last 
) [inline]

Insert a sublist immediately after this element.

Unlinks a chain of ListItem structures from whatever list they might be linked onto, and inserts them immediately after the subject ListItem.

Parameters:
before_first ListItem on the source list immediately preceding the starting ListItem of the chain to splice.
last Final ListItem on the source list of the chain to splice.

void SpliceBefore ( ListItem before_first,
ListItem last 
) [inline]

Insert a sublist immediately before this element.

Unlinks a chain of ListItem structures from whatever list they might be linked onto, and inserts them immediately before the subject ListItem.

Parameters:
before_first ListItem on the source list immediately preceding the starting ListItem of the chain to splice.
last Final ListItem on the source list of the chain to splice.

void PrependItemsFrom ( ListItem source  )  [inline]

Prepends all elements of a list into this.

Splices all items of source onto the beginning of the subject list. The parameter source is reinitialized as part of this operation. Upon return, source will be empty.

Parameters:
source List from which items should be transferred.

void AppendItemsFrom ( ListItem source  )  [inline]

Appends all elements of a list into this.

Splices all items of source onto the end of the subject list. The parameter source is reinitialized as part of this operation. Upon return, source will be empty.

Parameters:
source List from which items should be transferred.

int Length (  )  const [inline]

Compute the length of a list.

Determines how many items are linked into a list, not including the ListItem it is called on.


The documentation for this class was generated from the following file:
Generated on Fri Jan 9 05:58:41 2009 for libhfp by  doxygen 1.5.4