# dmd.backend.dlist

Interface to the C linked list type.

#### Discussion

List is a complete package of functions to deal with singly linked lists of pointers or integers.

Features:

1. Uses mem package.
2. Has loop-back tests.
3. Each item in the list can have multiple predecessors, enabling different lists to 'share' a common tail.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: backend/`dlist`.d

- `list_link`

  #### Declaration

  `nothrow @nogc @safe list_t `list_link`(list_t `list`);`

  Create link to existing `list`, that is, share the `list` with somebody else.

  #### Return Value

  pointer to that `list` entry.

- `list_next`

  #### Declaration

  `nothrow @nogc @safe list_t `list_next`(list_t `list`);`

  #### Return Value

  pointer to next entry in `list`.

- `list_ptr`

  #### Declaration

  `nothrow @nogc @trusted inout(void)* `list_ptr`(inout list_t `list`);`

  #### Return Value

  ptr from `list` entry.

- `list_data`

  #### Declaration

  `nothrow @nogc @safe int `list_data`(list_t `list`);`

  #### Return Value

  integer item from `list` entry.

- `list_appenddata`

  #### Declaration

  `nothrow @nogc @safe void `list_appenddata`(list_t* `plist`, int `d`);`

  Append integer item to list.

- `list_prependdata`

  #### Declaration

  `nothrow @nogc @safe void `list_prependdata`(list_t* `plist`, int `d`);`

  Prepend integer item to list.

- `list_init`

  #### Declaration

  `nothrow @nogc @trusted void `list_init`();`

  Initialize list package.

  Output: list_inited = 1

- `list_term`

  #### Declaration

  `nothrow @nogc @trusted void `list_term`();`

  Terminate list package.

  Output: list_inited = 0

- `list_free`

  #### Declaration

  `nothrow @nogc @trusted void `list_free`(list_t* `plist`, list_free_fp `freeptr`);`

  Free list.

  #### Parameters

  `list_t* `plist`` | Pointer to list to free
  `list_free_fp `freeptr`` | Pointer to freeing function for the data pointer (use FPNULL if none)

  Output: *`plist` is `null`

- `list_subtract`

  #### Declaration

  `nothrow @nogc @trusted void* `list_subtract`(list_t* `plist`, void* `ptr`);`

  Remove `ptr` from the list pointed to by *`plist`.

  Output: *`plist` is updated to be the start of the new list

  #### Return Value

  `null` if *`plist` is `null` otherwise `ptr`

- `list_pop`

  #### Declaration

  `nothrow @nogc @safe void* `list_pop`(list_t* `plist`);`

  Remove first element in list pointed to by *`plist`.

  #### Return Value

  First element, `null` if *`plist` is `null`

- `list_append`

  #### Declaration

  `nothrow @nogc @trusted list_t `list_append`(list_t* `plist`, void* `ptr`);`

  Append `ptr` to *`plist`.

  #### Return Value

  pointer to list item created. `null` if out of memory

- `list_prepend`

  #### Declaration

  `nothrow @nogc @trusted list_t `list_prepend`(list_t* `plist`, void* `ptr`);`

  Prepend `ptr` to *`plist`.

  #### Return Value

  pointer to list item created (which is also the start of the list). `null` if out of memory

- `list_nitems`

  #### Declaration

  `nothrow @nogc @safe int `list_nitems`(list_t `list`);`

  Count up and return number of items in `list`.

  #### Return Value

  # of entries in `list`

- `list_nth`

  #### Declaration

  `nothrow @nogc @safe list_t `list_nth`(list_t `list`, int `n`);`

  #### Return Value

  nth `list` entry in `list`.

- `list_last`

  #### Declaration

  `nothrow @nogc @safe list_t `list_last`(list_t `list`);`

  #### Return Value

  last `list` entry in `list`.

- `list_prev`

  #### Declaration

  `nothrow @nogc @safe list_t `list_prev`(list_t `start`, list_t `list`);`

  #### Return Value

  pointer to previous item in `list`.

- `list_copy`

  #### Declaration

  `nothrow @nogc @trusted list_t `list_copy`(list_t `list`);`

  Copy a `list` and return it.

- `list_equal`

  #### Declaration

  `nothrow @nogc @safe int `list_equal`(list_t `list1`, list_t `list2`);`

  Compare two lists.

  #### Return Value

  If they have the same ptrs, return 1 else 0.

- `list_cmp`

  #### Declaration

  `nothrow @nogc @trusted int `list_cmp`(list_t `list1`, list_t `list2`, int function(void*, void*) nothrow @nogc `fp`);`

  Compare two lists using the comparison function `fp`. The comparison function is the same as used for qsort().

  #### Return Value

  If they compare equal, return 0 else value returned by `fp`.

- `list_inlist`

  #### Declaration

  `nothrow @nogc @trusted list_t `list_inlist`(list_t `list`, void* `ptr`);`

  Search for `ptr` in `list`.

  #### Return Value

  If found, return `list` entry that it is, else `null`.

- `list_cat`

  #### Declaration

  `nothrow @nogc @safe list_t `list_cat`(list_t* `pl1`, list_t `l2`);`

  Concatenate two lists (`l2` appended to l1).

  Output: *`pl1` updated to be start of concatenated list.

  #### Return Value

  *`pl1`

- `list_apply`

  #### Declaration

  `nothrow @nogc @trusted void `list_apply`(list_t* `plist`, void function(void*) nothrow @nogc `fp`);`

  Apply a function `fp` to each member of a list.

- `list_reverse`

  #### Declaration

  `nothrow @nogc @safe list_t `list_reverse`(list_t `l`);`

  Reverse a list in place.

- `list_copyinto`

  #### Declaration

  `nothrow @nogc @trusted void `list_copyinto`(list_t `l`, void* `pa`);`

  Copy list of pointers into an array of pointers.

- `list_insert`

  #### Declaration

  `nothrow @nogc @trusted list_t `list_insert`(list_t* `pl`, void* `ptr`, int `n`);`

  Insert item into list at nth position.

- `ListRange`

  #### Declaration

  `struct `ListRange`;`

  Range for Lists.

- `list_build`

  #### Declaration

  `nothrow @trusted list_t `list_build`(void* `p`, ...);`

  Build a list out of the `null`-terminated argument list.

  #### Return Value

  generated list