Doubly linked list API

group Linked list API

A doubly linked list API based on BSD/UNIX

Defines

A_LIST_HEAD(name)

Declare and initialize a doubly linked list head

See also

a_list_init for the runtime variant

Parameters:
  • name – The name of the list

a_list_entry(e, type, field)

Get the full element of a doubly linked list element

Parameters:
  • e – The list element

  • type – The type of the containing structure

  • field – The name of the struct a_list_head element in the containing structure

Returns:

A pointer to the full list element of type

a_list_first_entry(head, type, field)

Get the full element of the first entry in a doubly linked list head

Parameters:
  • head – The doubly linked list head

  • type – The type of the containing structure

  • field – The name of the struct a_list_head element in the containing structure

Returns:

A pointer to the full list element of type

a_list_last_entry(head, type, field)

Get the full element of the last entry in a doubly linked list head

Parameters:
  • head – The doubly linked list head

  • type – The type of the containing structure

  • field – The name of the struct a_list_head element in the containing structure

Returns:

A pointer to the full list element of type

a_list_for_each(p, head)

Iterate over a doubly linked list

See also

a_list_for_each_safe for the version that is modification safe.

Warning

It is not safe to modify the list when iterating with this iterator.

Parameters:
  • p – A struct a_list_head pointer to hold the current element

  • head – The list head to iterate over

a_list_for_each_safe(p, n, head)

Iterate over a doubly linked list safely for modification of the list

See also

a_list_for_each for the version that is only for iteration.

Parameters:
  • p – A struct a_list_head pointer to hold the current element

  • n – A struct a_list_head pointer to hold the next element

  • head – The list head to iterate over

a_list_for_each_entry(p, head, field)

Iterate over a doubly linked list, with full elements

See also

a_list_for_each_element_safe for the version that is modification safe.

Warning

It is not safe to modify the list when iterating with this iterator.

Parameters:
  • p – A pointer of the full element type to hold the current element

  • head – The list head to iterate over

  • field – The name of the struct a_list_head member in the containing structure

a_list_for_each_entry_safe(p, n, head, field)

Iterate over a doubly linked list safely for modification of the list, with full elements

See also

a_list_for_each_entry for the version that is only for iteration.

Parameters:
  • p – A pointer of the full element type to hold the current element

  • n – A pointer of the full element type to hold the next element

  • head – The list head to iterate over

  • field – The name of the struct a_list_head member in the containing structure

Functions

static inline void a_list_init(struct a_list_head *list)

Run-time initialize a doubly linked list head

Initialize a struct a_list_head object.

See also

A_LIST_HEAD for the compile time variant

Parameters:
  • list – The list head

static inline bool a_list_empty(struct a_list_head *list)

Test if a doubly linked list is empty

Parameters:
  • list – The list head

Returns:

true is empty, else false

static inline void a_list_add(struct a_list_head *e, struct a_list_head *head)

Add an element to the start of a doubly linked list

The element gets added first in the list.

See also

a_list_add_tail for the version that adds the element last.

Parameters:
  • e – The element to add

  • head – The list to add the element to

static inline void a_list_add_tail(struct a_list_head *e, struct a_list_head *head)

Add an element to the end of doubly linked list

The element gets added last in the list.

See also

a_list_add for the version that adds the element first.

Parameters:
  • e – The element to add

  • head – The list to add the element to

static inline void a_list_del(struct a_list_head *e)

Delete an element from a doubly linked list

Parameters:
  • e – The element to delete

static inline void a_list_move(struct a_list_head *e, struct a_list_head *head)

Move an element to the start of another doubly linked list

The element gets added first in the list.

See also

a_list_move_tail for the version that adds the element last.

Parameters:
  • e – The element to move

  • head – The list to add the element to

static inline void a_list_move_tail(struct a_list_head *e, struct a_list_head *head)

Move an element to the end of another doubly linked list

The element gets added last in the list.

See also

a_list_move for the version that adds the element first.

Parameters:
  • e – The element to move

  • head – The list to add the element to

static inline void a_list_splice(struct a_list_head *list, struct a_list_head *head)

Merge a doubly linked list into another doubly linked list

list will be added before the elements pointed to by head .

See also

a_list_splice_tail for the version that adds the elements to the end.

Parameters:
  • list – The list to merge

  • head – The list to merge into

static inline void a_list_splice_tail(struct a_list_head *list, struct a_list_head *head)

Merge a doubly linked list into another doubly linked list

list will be added after the elements pointed to by head .

See also

a_list_splice for the version that adds the elements to the front.

Parameters:
  • list – The list to merge

  • head – The list to merge into

struct a_list_head

A doubly linked list head

Serves both as the list head and list nodes when embedded in a structure.