Data Structures | Files | Defines | Typedefs | Functions

EGeList

Data Structures

struct  EGeList_t
 List Node Structure. More...
struct  integer_list_t
 example of integer number lists structure based on embeded lists. More...

Files

file  eg_elist.ex.c
file  eg_elist.h

Defines

#define __EGeListAdd(__newpt, __prevpt, __nextpt)
 Insert a __newpt __entry between two known consecutive entries.
#define __EGeListLink(__prevpt, __nextpt)
 Given two nodes, link them as if they would follow one another in the list (used to delete points from a list).
#define __EGeListSplice(__list, __head)
 move all elements in one list to the given location in a second list. Note that this function assumes that the list is represented by a pointer to an EGeList_t structure that act as a marker but that don't bellong to the list, and thus is not included in the joinded list.
#define __EL_DEBUG_   100
 debug level for lists
#define EGeListAddAfter(__newpt, __head)   __EGeListAdd(__newpt,__head,(__head)->next)
 Insert a __newpt __entry after the given pointer.
#define EGeListAddBefore(__newpt, __tailpt)   __EGeListAdd(__newpt,(__tailpt)->prev,__tailpt)
 Insert a __newpt __entry before the given pointer.
#define EGeListDel(__entry)
 Given a node, eliminate it from the list it bellongs. but don't change the internal data in the eliminated list (be carefull, if you will use it afterwards, then you MUST initialize it). If debugging is enabled, then whenever you delete, the connector is reseted to 0xffffffff. What you can count on is that the connector won't be NULL after deleting it from the list, but it's values may be lost if we are debugging.
#define EGeListInit(__lpt)
 Initialize a given structure to point to itself (in circular fashion).
#define EGeListIsEmpty(__head)
 test whether a list is empty (i.e. he is its own next pointer)
#define EGeListMoveAfter(__entry, __head)
 Move an element from one list to another (deleting it from the original one).
#define EGeListMoveBefore(__entry, __tailpt)
 Move an element from one list to another (deleting it from the original one).
#define EGeListReplace(__oldpt, __newpt)
 Replace one __entry with another in a list.
#define EGeListSplice(__list, __head)   ({if(!EGeListIsEmpty(__list)) __EGeListSplice(__list,__head);})

Typedefs

typedef struct EGeList_t EGeList_t
 List Node Structure.

Functions

int main (void)
 A simple example of using embeded lists.

Detailed Description

Here we define the basic interface for a circular linked list where the list is embeded in some other structure. The ideas come from the Linux Kernel implementation of lists. This implementation is based on the philosophy of embeded structures.

Version:
0.0.1
History:
  • 2005-08-19
    • Add debugging control
  • 2005-05-23
    • First Implementation.
Note:
In general, the functions described bellow don't perform consistency checks. It is asumed that the user does know what is he doing.
If you want to have some debugging control try changing the debug level at compile time, and lowering the debug level asociated to the list function as defined in eg_configure.h.

Define Documentation

#define __EGeListAdd (   __newpt,
  __prevpt,
  __nextpt 
)
Value:
({\
  EGeList_t*const __EGeL_add_new = (__newpt);\
  EGeList_t*const __EGeL_add_prev = (__prevpt);\
  EGeList_t*const __EGeL_add_next = (__nextpt);\
  __EGeL_add_next->prev = __EGeL_add_new;\
  __EGeL_add_prev->next = __EGeL_add_new;\
  __EGeL_add_new->next = __EGeL_add_next;\
  __EGeL_add_new->prev = __EGeL_add_prev;\
  __EGeL_add_new;})

Insert a __newpt __entry between two known consecutive entries.

Description:
This is only for internal list manipulation, where we know the prev/next entries already.
Parameters:
__newpt pointer to the list node to insert.
__prevpt pointer to the node to preceed the __newpt node.
__nextpt pointer to the node to follow the __newpt node.
Returns:
the address of __newpt.

Definition at line 93 of file eg_elist.h.

#define __EGeListLink (   __prevpt,
  __nextpt 
)
Value:
({\
  EGeList_t* __EGeL_lnk_prev = (__prevpt);\
  EGeList_t* __EGeL_lnk_next = (__nextpt);\
  __EGeL_lnk_prev->next = __EGeL_lnk_next;\
  __EGeL_lnk_next->prev = __EGeL_lnk_prev;\
  0;})

Given two nodes, link them as if they would follow one another in the list (used to delete points from a list).

Parameters:
__prevpt pointer to the guy to be in first in the list.
__nextpt pointer to the guy to follow in the list.
Description:
This function is intended to be used only internally, where we know what is what, if you use it is because you also know what is going on.

Definition at line 128 of file eg_elist.h.

#define __EGeListSplice (   __list,
  __head 
)
Value:
({\
  EGeList_t* __EGeL_spl_list = (__list);\
  EGeList_t* __EGeL_spl_first = __EGeL_spl_list->next;\
  EGeList_t* __EGeL_spl_last = __EGeL_spl_list->prev;\
  EGeList_t* __EGeL_spl_head = (__head);\
  EGeList_t* __EGeL_spl_at = __EGeL_spl_head->next;\
  __EGeL_spl_first->prev = __EGeL_spl_head;\
  __EGeL_spl_head->next = __EGeL_spl_first;\
  __EGeL_spl_last->next = __EGeL_spl_at;\
  __EGeL_spl_at->prev = __EGeL_spl_last;\
  0;})

move all elements in one list to the given location in a second list. Note that this function assumes that the list is represented by a pointer to an EGeList_t structure that act as a marker but that don't bellong to the list, and thus is not included in the joinded list.

Parameters:
__list marker to the list to be joined with the second. Note that the fields in list won't be reinitialized, so be carefull with that, because the fields are pointing to inconsistent data as it is, if you want to reutilize the list you must call EGeListInit before.
__head position from where the list will be spliced in.
Note:
Note that the original list is left in an undefined status, so before use it, it should be re-initialized.

Definition at line 210 of file eg_elist.h.

#define __EL_DEBUG_   100

debug level for lists

Definition at line 59 of file eg_elist.h.

#define EGeListAddAfter (   __newpt,
  __head 
)    __EGeListAdd(__newpt,__head,(__head)->next)

Insert a __newpt __entry after the given pointer.

Parameters:
__newpt pointer to the __newpt list node to insert.
__head pointer from where the __newpt __entry will follow.
Returns:
the pointer to the __newpt __entry in the list.
Examples:
eg_min_cut.ex.c.

Definition at line 109 of file eg_elist.h.

Referenced by EGalgMCcomputeT(), EGalgPRcomputeLabels(), EGalgPRglobalRelabel(), EGalgPRpush(), EGalgPRpushRelabel(), and main().

#define EGeListAddBefore (   __newpt,
  __tailpt 
)    __EGeListAdd(__newpt,(__tailpt)->prev,__tailpt)

Insert a __newpt __entry before the given pointer.

Parameters:
__newpt pointer to the __newpt list node to insert.
__tailpt pointer that will follow the __newpt __entry in the list.
Returns:
the pointer to the __newpt __entry in the list.
Examples:
eg_elist.ex.c.

Definition at line 117 of file eg_elist.h.

Referenced by main().

#define EGeListDel (   __entry  ) 
Value:
({\
  EGeList_t *const __EGeL_del_entr = (__entry);\
  __EGeListLink(__EGeL_del_entr->prev,__EGeL_del_entr->next);\
  if(__EL_DEBUG_ <= DEBUG) \
    (*__EGeL_del_entr) = (EGeList_t){(EGeList_t*)0xffffffffU,\
                                     (EGeList_t*)0xffffffffU};\
  __EGeL_del_entr;})

Given a node, eliminate it from the list it bellongs. but don't change the internal data in the eliminated list (be carefull, if you will use it afterwards, then you MUST initialize it). If debugging is enabled, then whenever you delete, the connector is reseted to 0xffffffff. What you can count on is that the connector won't be NULL after deleting it from the list, but it's values may be lost if we are debugging.

Parameters:
__entry __entry to eliminate from the list.
Returns:
pointer to the deleted __entry from the list.
Examples:
eg_elist.ex.c.

Definition at line 144 of file eg_elist.h.

Referenced by EGalgMCcomputeT(), EGalgPRcomputeLabels(), EGalgPRnumb(), EGalgPRpreprocess(), EGalgPRpushRelabel(), and main().

#define EGeListInit (   __lpt  ) 
Value:
({\
  EGeList_t*const __EGeL_init =(__lpt);\
  __EGeL_init->next = __EGeL_init->prev = __EGeL_init;})

Initialize a given structure to point to itself (in circular fashion).

Parameters:
__lpt pointer to the list to initialize.
Returns:
the pointer to the list.
Examples:
eg_elist.ex.c.

Definition at line 79 of file eg_elist.h.

Referenced by EGalgMCcomputeT(), EGalgPRcomputeLabels(), EGalgPRglobalRelabel(), EGalgPRminSTcut(), EGalgPRoptimalityTest(), and main().

#define EGeListIsEmpty (   __head  ) 
Value:
({\
  EGeList_t* __EGeL_emp_head = (__head);\
  (__EGeL_emp_head == __EGeL_emp_head->next);})

test whether a list is empty (i.e. he is its own next pointer)

Examples:
eg_edgraph.ex.c, eg_elist.ex.c, eg_eugraph.ex.c, and eg_shrink_graph.ex.c.

Definition at line 193 of file eg_elist.h.

Referenced by display_DG(), display_srkG(), display_UG(), EGalgMCcomputeT(), EGalgPRcomputeLabels(), EGalgPRmaxSTflow(), EGalgPRminSTcut(), and main().

#define EGeListMoveAfter (   __entry,
  __head 
)
Value:
({\
  __EGeListLink((__entry)->prev,(__entry)->next);\
  EGeListAddAfter(__entry,__head);})

Move an element from one list to another (deleting it from the original one).

Parameters:
__entry element to be removed from it's current list to a position after the given __head.
__head element to be before the moved element.

Definition at line 176 of file eg_elist.h.

Referenced by EGalgPRpushRelabel().

#define EGeListMoveBefore (   __entry,
  __tailpt 
)
Value:
({\
  __EGeListLink((__entry)->prev,(__entry)->next);\
  EGeListAddBefore(__entry,__tailpt);})

Move an element from one list to another (deleting it from the original one).

Parameters:
__entry element to be removed from it's current list to a position before the given __tailpt.
__tailpt element to be after the moved element.
Examples:
eg_elist.ex.c.

Definition at line 187 of file eg_elist.h.

Referenced by main().

#define EGeListReplace (   __oldpt,
  __newpt 
)
Value:
({\
  EGeList_t* __EGeL_rep_old = (__oldpt);\
  EGeList_t* __EGeL_rep_new = (__newpt);\
  __EGeL_rep_new->next = __EGeL_rep_old->next;\
  __EGeL_rep_new->prev = __EGeL_rep_old->prev;\
  __EGeL_rep_new->next->prev = __EGeL_rep_new;\
  __EGeL_rep_new->prev->next = __EGeL_rep_new;\
  __EGeL_rep_old;})

Replace one __entry with another in a list.

Parameters:
__oldpt __entry to be replaced, note that the pointers stored in next/prev won't be changed, this may possible lead to errors if the __entry is used afterwards without initialization.
__newpt __newpt __entry in the list.
Returns:
pointer to the old replaced member.
Examples:
eg_elist.ex.c.

Definition at line 160 of file eg_elist.h.

Referenced by main().

#define EGeListSplice (   __list,
  __head 
)    ({if(!EGeListIsEmpty(__list)) __EGeListSplice(__list,__head);})
Examples:
eg_elist.ex.c.

Definition at line 221 of file eg_elist.h.

Referenced by main().


Typedef Documentation

typedef struct EGeList_t EGeList_t

List Node Structure.

Description:
This structure is to store a general node of the list. It is composed by two members, that point to the next and previous structures in the list.

Function Documentation

int main ( void   ) 

A simple example of using embeded lists.

Returns:
zero on success, non-zero otherwise.
Description:
Show how to use embeded lists in a dynamic way and in a static fashion.

Definition at line 40 of file eg_elist.ex.c.

References integer_list_t::cn, EGcontainerOf, EGeListAddBefore, EGeListDel, EGeListInit, EGeListIsEmpty, EGeListMoveBefore, EGeListReplace, EGeListSplice, EGlib_info(), EGlib_version(), EGrand(), EGrandInit(), EGsetLimits(), EGsigSet, g, integer_list_t::n, and EGeList_t::next.

Here is the call graph for this function: