|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Doubly linked circular list implementation. More...
Go to the source code of this file.
Classes | |
| class | Aleph::Dlink |
| Doubly linked circular list node. More... | |
| class | Aleph::Dlink::Iterator |
Iterator on Dlink lists. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Macros | |
| #define | DLINK_TO_TYPE(type_name, link_name) |
Generate a conversion function from a Dlink field to a class containing it. | |
| #define | LINKNAME_TO_TYPE(type_name, link_name) |
Generate a conversion function from a Dlink field pointer to a pointer to the class containing it. | |
| #define | DLINK_TO_BASE(type_name, link_name) |
Generate a function with name link_to_base() what converts a Dlink pointer to the class or struct that contains it. | |
Doubly linked circular list implementation.
This file provides the Dlink class, a low-level building block for doubly linked circular lists with a sentinel header node. The design allows O(1) insertion and removal at any position, and O(1) list concatenation and splitting.
The circular design with sentinel node simplifies boundary conditions and enables symmetric forward/backward traversal.
Definition in file dlink.H.
| #define DLINK_TO_BASE | ( | type_name, | |
| link_name | |||
| ) |
Generate a function with name link_to_base() what converts a Dlink pointer to the class or struct that contains it.
This macro could be used when a class have a Dlink field y and from it it is desired to get a pointer to the class. For example, suppose some such as:
struct Record { ... Dlink l; ... };
Then DLINK_TO_BASE(Record, l) will produce the function:
Record * dlink_to_base(Dlink * link)
which receives a pointer to the Dlink field l and return a pointer to the Record object storing l.
| type_name | the name of class of struct containing the Dlink field. |
| link_name | the name of Dlink field inside the class or struct |
| #define DLINK_TO_TYPE | ( | type_name, | |
| link_name | |||
| ) |
Generate a conversion function from a Dlink field to a class containing it.
This macro is used when inside a class exists one o more Dlink fields and it is needed to obtain from a Dlink field a pointer to the class containing it.
For example, suppose the following situation:
struct Record { ... Dlink l; ... };
So, DLINK_TO_TYPE(Record, l) will generate the function:
Record * dlink_to_Record(Dlink * link)
which receives a pointer to the Dlink field l and returns a pointer to the class Record containing l.
| type_name | the name of class or struct containing the Dlink field |
| link_name | the name of the Dlink field inside the class or struct. |
| #define LINKNAME_TO_TYPE | ( | type_name, | |
| link_name | |||
| ) |
Generate a conversion function from a Dlink field pointer to a pointer to the class containing it.
The name of the function is literally the name of second parameter
This macro is used when one o more Dlink field are used inside a class and it is desired to obtain pointers to the class from the Dlink fields. Consider for example,
struct Redcordgistro { ... Dlink l1; Dlink l2; ... };
So, LINKNAME_TO_TYPE(Record, l1) and LINKNAME_TO_TYPE(Record, l2) will generate the following functions:
Record * l1_to_type(Dlink * link)
Record * l2_to_type(Dlink * link)
So for converting a Dlink pointer to l1 to a pointer to Record object which contains it, you use l1_to_type(link); analogously with l2_to_type(link).
The idea is having naming schemes allowing to distinguish several Dlink fields.
Dlink fields. This situation arises if you want that the class simultaneously belongs to several lists. In this case you would declare a Dlink field by each different list.| type_name | the name of struct or class containing to the Dlink object. |
| link_name | the name of Dlink field |