Di_slist

## Data Structures

struct | di_slist
| Single-linked list. More...
struct | di_slist_node
| Node of a single-linked list. More...

## Functions

di_slist * | di_slist_alloc (void)
void | di_slist_destroy (di_slist *slist, di_destroy_notify destroy_func) __attribute__((nonnull(1)))
void | di_slist_free (di_slist *slist)
void | di_slist_append (di_slist *slist, void *data) __attribute__((nonnull(1)))
void | di_slist_append_chunk (di_slist *slist, void *data, di_mem_chunk *mem_chunk) __attribute__((nonnull(1
void void | di_slist_prepend (di_slist *slist, void *data) __attribute__((nonnull(1)))
void | di_slist_prepend_chunk (di_slist *slist, void *data, di_mem_chunk *mem_chunk) __attribute__((nonnull(1
void | internal_di_slist_append_list (di_slist *slist, di_slist *slist_append)

## Detailed Description

## Function Documentation

## di_slist_alloc()

di_slist* di_slist_alloc | ( | void |  | ) |

Allocate a single-linked list

Returns
  a di_slist

{
di_slist *slist;
slist = di_new0 (di_slist, 1);
return slist;
}
di_new0
#define di_new0(struct_type, n_structs)
Definition: mem.h:79
di_slist
Single-linked list.
Definition: slist.h:37

References di_new0.

## di_slist_append()

void di_slist_append | ( | di_slist * | slist,
|  | void * | data
| ) |  |

Append to a single-linked list

Warning
  don't mix with di_slist_append_chunk

Parameters

  slist | a di_slist
  data | the data

{
return internal_di_slist_append (slist, data, di_new (di_slist_node, 1));
}
di_new
#define di_new(struct_type, n_structs)
Definition: mem.h:73
di_slist_node
Node of a single-linked list.
Definition: slist.h:46

References di_new.

## di_slist_append_chunk()

void di_slist_append_chunk | ( | di_slist * | slist,
|  | void * | data,
|  | di_mem_chunk * | mem_chunk
| ) |  |

Append to a single-linked list

Warning
  don't mix with di_slist_append

Parameters

  slist | a di_slist
  data | the data
  mem_chunk | a di_mem_chunk for allocation of new nodes

Precondition
  the di_mem_chunk must return chunks with at least the size of di_slist_node

Referenced by di_packages_append_package().

## di_slist_destroy()

void di_slist_destroy | ( | di_slist * | slist,
|  | di_destroy_notify | destroy_func
| ) |  |

Destroy the contents of a single-linked list

Warning
  never use this function with a list which makes use of the chunk allocator

Parameters

  slist | a di_slist

{
di_slist_node *node, *temp;
node = slist->head;
while (node)
{
temp = node;
node = node->next;
if (destroy_func)
destroy_func (temp->data);
di_free (temp);
}
}
di_free
void di_free(void *mem)
Definition: mem.c:60
di_slist_node::next
di_slist_node * next
Definition: slist.h:47
di_slist_node::data
void * data
Definition: slist.h:48
di_slist::head
di_slist_node * head
Definition: slist.h:38

References di_slist_node::data, di_free(), head, and di_slist_node::next.

## di_slist_free()

void di_slist_free | ( | di_slist * | slist | ) |

Free a single-linked list

Parameters

  slist | a di_slist

{
di_free (slist);
}

References di_free().

## di_slist_prepend()

void void di_slist_prepend | ( | di_slist * | slist,
|  | void * | data
| ) |  |

Prepend to a single-linked list

Warning
  don't mix with di_slist_prepend_chunk

Parameters

  slist | a di_slist
  data | the data

{
return internal_di_slist_prepend (slist, data, di_new (di_slist_node, 1));
}

References di_new.

## di_slist_prepend_chunk()

void di_slist_prepend_chunk | ( | di_slist * | slist,
|  | void * | data,
|  | di_mem_chunk * | mem_chunk
| ) |  |

Prepend to a single-linked list

Warning
  don't mix with di_slist_prepend

Parameters

  slist | a di_slist
  data | the data
  mem_chunk | a di_mem_chunk for allocation of new nodes

Precondition
  the di_mem_chunk must return chunks with at least the size of di_slist_node

## internal_di_slist_append_list()

void internal_di_slist_append_list | ( | di_slist * | slist,
|  | di_slist * | slist_append
| ) |  |

{
if (!new->head || !new->bottom)
return;
if (slist->bottom)
slist->bottom->next = new->head;
else
slist->head = new->head;
slist->bottom = new->bottom;
new->head = new->bottom = NULL;
}
di_slist::bottom
di_slist_node * bottom
Definition: slist.h:39

References bottom, head, and di_slist_node::next.