Intrusive Containers
Loading...
Searching...
No Matches

Intrusive Singly Linked List. More...

#include "Container.h"
Include dependency graph for ListIn.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ListInNode< R, N, s, n >
 Intrusive Singly Linked List, Node. More...
 
class  ListInRoot< R, N, s, n >
 Intrusive Singly Linked List, List. More...
 

Detailed Description

Intrusive Singly Linked List.

This file defines a pair of templates (ListInRoot and ListInNode) that implement an intrusive singly linked list.

Overview

ListInRoot and ListInNode provide a simple API to allow classes to provide a basic List <-> Node relationship (1 List holding many Nodes), with a singly linked list. (c.f. DListin.h, DListInRoot, and DListInNode for doubly linked list)

To create this relationship, the class to act as the list derives from the template ListInRoot, and the class to act as the Node from ListInNode, both with a first parameter of the class name of the List class, and a second parameter of the Node class. There is an optional integral 3rd parameter to allow the classes to inherent from these multiple times if you need to represent multiple simultaneous relationships. This inheritance should be public, or you need to add the ListInRoot and ListInNode templates as friends.

At the point of declaration, both classes need to be declared, so you will typically have a forward of the other class before the definition of the class. At the point of usage of members, generally the full definition of both classes is needed to instance the code for the template.

Inside this file, the following types have the following meanings:

R: The "user" type that will be derived from ListInRoot

N: The "user" type that will be derived from ListInNode

n: The integer parameter for the template to allow multiple usage

Root: The particular instance of ListInRoot<R, N, n> being used

Node: The particular instance of ListInNode<R, N, n> being used

node: will have type N*, to be used when walking the list.

Invariant

Given:

  • R& root
  • N& node

ListInRoot:

  • if root.m_first == nullptr
    • root.m_last == nullptr
  • if root.m_first !- nullptr
    • root,m_last != nullotr
    • root.m_first->m_root == &root
    • root.m_last->m_root == &root
    • root.m_last->m_next == nullptr

ListInNode:

  • if node.m_root == nullptr
    • node.m_nest == nullptr
  • if node.m_next == nullptr
    • node.m_root->m_last = &node;
  • if node.m_next != nullptr
    • node.m_next->m_root == node.m_root
    • node.m_next != node.m_root->m_first

Last Criteria is closet expression to the fact that root.m_first points to a node that other node points to as its m_next

See also
DListIn.h