SourcePro® 2024.1 |
SourcePro® API Reference Guide |
Implements intrusive singly-linked lists. More...
#include <rw/tislist.h>
Inherits RWIsvSlist.
Public Member Functions | |
RWTIsvSlist () | |
RWTIsvSlist (RWTIsvSlist &&lst) | |
RWTIsvSlist (TL *a) | |
void | append (TL *a) |
void | apply (void(*applyFun)(TL *, void *), void *d) |
TL * | at (size_t i) const |
void | clear () |
void | clearAndDestroy () |
bool | contains (bool(*testFun)(const TL *, void *), void *d) const |
bool | containsReference (const TL *a) const |
size_t | entries () const |
TL * | find (bool(*testFun)(const TL *, void *), void *d) const |
TL * | first () const |
TL * | get () |
size_t | index (bool(*testFun)(const TL *, void *), void *d) const |
void | insert (TL *a) |
void | insertAt (size_t i, TL *a) |
bool | isEmpty () const |
TL * | last () const |
size_t | occurrencesOf (bool(*testFun)(const TL *, void *), void *d) const |
size_t | occurrencesOfReference (const TL *a) const |
RWTIsvSlist & | operator= (RWTIsvSlist &&lst) |
void | prepend (TL *a) |
TL * | remove (bool(*testFun)(const TL *, void *), void *d) |
TL * | removeAt (size_t i) |
TL * | removeFirst () |
TL * | removeLast () |
TL * | removeReference (TL *a) |
void | swap (RWTIsvSlist< TL > &lst) |
Friends | |
class | RWTIsvSlistIterator< TL > |
Class RWTIsvSlist implements intrusive singly-linked lists.
An intrusive list requires that all members of the list inherit from a common base class, in this case RWIsvSlink. The advantage of such a list is that memory and space requirements are minimized. The disadvantage is that the inheritance hierarchy is inflexible, possibly complicating its use with an existing class. Class RWTValSlist is offered as an alternative, non-intrusive, linked list.
This class is not CopyConstructible or CopyAssignable but is MoveConstructible and MoveAssignable.
See Stroustrup (1991; Section 8.3.1) for more information about intrusive lists.
Note that when you insert an item into an intrusive list, the actual item (not a copy) is inserted. Because each item carries only one link field, the same item cannot be inserted into more than one list, nor can it be inserted into the same list more than once.
Program Output:
|
inline |
Constructs an empty list.
|
inline |
Constructs a list containing the single item pointed to by a.
|
inline |
Move constructor. The constructed RWTIsvDlist takes ownership of the data owned by lst.
|
inline |
Appends the item pointed to by a to the end of the list.
void RWTIsvSlist< TL >::apply | ( | void(* | applyFun )(TL *, void *), |
void * | d ) |
Calls the function pointed to by applyFun to every item in the collection. The item will be passed in as argument item
. Client data may be passed through as parameter d.
|
inline |
Returns the item at index i.
RWBoundsErr | Thrown if the index i is not between zero and the number of items in the collection less one. |
|
inline |
Removes all items from the list.
void RWTIsvSlist< TL >::clearAndDestroy | ( | ) |
Removes and calls delete for each item in the list. Note that this assumes that each item was allocated off the heap.
|
inline |
Returns true
if the list contains an item for which the user-defined function pointed to by testFun returns true
.
For each item in the list, this function is called with the item as the first argument. Client data may be passed through as parameter d.
|
inline |
Returns true
if the list contains an item with the address a.
|
inline |
Returns the number of items currently in the list.
TL * RWTIsvSlist< TL >::find | ( | bool(* | testFun )(const TL *, void *), |
void * | d ) const |
Returns the first item in the list for which the user-defined function pointed to by testFun returns true
. If there is no such item, then returns rwnil.
For each item in the list, this function is called with the item as the first argument. Client data may be passed through as parameter d.
|
inline |
Returns (but does not remove) the first item in the list, or rwnil if the list is empty.
|
inline |
Returns and removes the first item in the list, or rwnil if the list is empty.
size_t RWTIsvSlist< TL >::index | ( | bool(* | testFun )(const TL *, void *), |
void * | d ) const |
Returns the index of the first item in the list for which the user-defined function pointed to by testFun returns true
. If there is no such item, then returns RW_NPOS.
For each item in the list, this function is called with the item as the first argument. Client data may be passed through as parameter d.
|
inline |
Appends the item pointed to by a to the end of the list. This item cannot be inserted into more than one list, nor can it be inserted into the same list more than once.
|
inline |
Inserts the item pointed to by a at the index position i.
The item cannot be inserted into more than one list, nor can it be inserted into the same list more than once.
RWBoundsErr | Thrown if the index i is not between zero and the number of items in the list. |
|
inline |
Returns true
if there are no items in the list, false
otherwise.
|
inline |
Returns (but does not remove) the last item in the list, or rwnil if the list is empty.
size_t RWTIsvSlist< TL >::occurrencesOf | ( | bool(* | testFun )(const TL *, void *), |
void * | d ) const |
Traverses the list and returns the number of times for which the user-defined function pointed to by testFun returned true
.
For each item in the list, this function is called with the item as the first argument. Client data may be passed through as parameter d.
|
inline |
Returns the number of times which the item pointed to by a occurs in the list. Because items cannot be inserted into a list more than once, this function can return only zero or one.
|
inline |
Move assignment. Self takes ownership of the data owned by lst.
|
inline |
Prepends the item pointed to by a to the beginning of the list.
TL * RWTIsvSlist< TL >::remove | ( | bool(* | testFun )(const TL *, void *), |
void * | d ) |
Removes and returns the first item for which the user-defined function pointed to by testFun returns true
, or rwnil if there is no such item.
For each item in the list, this function is called with the item as the first argument. Client data may be passed through as parameter d.
|
inline |
Removes and returns the item at index i.
RWBoundsErr | Thrown if the index i is not between zero and the number of items in the collection less one. |
|
inline |
Removes and returns the first item in the list, or rwnil if there are no items in the list.
|
inline |
Removes and returns the last item in the list, or rwnil if there are no items in the list. Note that this function is relatively slow because the enter list must be searched in order to remove of the last link in a singly-linked list.
|
inline |
Removes and returns the link with address a. The link must be in the list. In a singly-linked list this function is not very efficient.
|
inline |
Swaps the data owned by self with the data owned by lst.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |