Doubly-linked list.  
More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "list.h"
Go to the source code of this file.
|  | 
| List * | list_new (CompareFunc compare, FreeFunc free, Pool *pool) | 
|  | 
| void | list_init (List *list, CompareFunc compare, FreeFunc free, Pool *pool) | 
|  | 
| void | list_free (List *list) | 
|  | 
| void | list_destroy (List *list) | 
|  | 
| ListItem * | list_append (List *list, void *data) | 
|  | 
| ListItem * | list_prepend (List *list, void *data) | 
|  | 
| ListItem * | list_insert_sorted (List *list, void *data) | 
|  | 
| void | list_remove (List *list, ListItem *item) | 
|  | 
| void | list_remove_by_data (List *list, void *data, bool remove_all) | 
|  | 
| void * | list_pop (List *list) | 
|  | 
| bool | list_contains (const List *list, const void *data) | 
|  | 
| void | list_clear (List *list) | 
|  | 
| ListItem * | list_find (const List *list, ListItem *offset, void const *data) | 
|  | 
| ListItem * | list_head (const List *list) | 
|  | 
| ListItem * | list_tail (const List *list) | 
|  | 
| size_t | list_count (const List *list) | 
|  | 
| bool | list_empty (const List *list) | 
|  | 
| void | list_item_free_data (const List *list, ListItem *item) | 
|  | 
◆ list_append()
- Parameters
- 
  
    | list | a List |  | data | data to append |  
 
- Returns
- a new ListItem
Appends data to the list. 
Definition at line 133 of file list.c.
 
 
◆ list_clear()
      
        
          | void list_clear | ( | List * | list | ) |  | 
      
 
- Parameters
- 
  
  
Clears a list. 
Definition at line 402 of file list.c.
 
 
◆ list_contains()
      
        
          | bool list_contains | ( | const List * | list, | 
        
          |  |  | const void * | data | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
  
- Returns
- true if data exists in list
Tests if a list contains the specified data. 
Definition at line 393 of file list.c.
 
 
◆ list_count()
      
        
          | size_t list_count | ( | const List * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- number of items
Gets the number of items. 
Definition at line 438 of file list.c.
 
 
◆ list_destroy()
      
        
          | void list_destroy | ( | List * | list | ) |  | 
      
 
- Parameters
- 
  
  
Frees all items in the list and the list pointer. 
Definition at line 98 of file list.c.
 
 
◆ list_empty()
      
        
          | bool list_empty | ( | const List * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- true if list is empty
Checks if a list is empty. 
Definition at line 446 of file list.c.
 
 
◆ list_find()
- Parameters
- 
  
    | list | a List |  | offset | position to start search from |  | data | data to search |  
 
- Returns
- found ListItem or NULL
Searches for the specified data. 
Definition at line 414 of file list.c.
 
 
◆ list_free()
      
        
          | void list_free | ( | List * | list | ) |  | 
      
 
- Parameters
- 
  
  
Frees all items in the list without freeing the list pointer. 
Definition at line 81 of file list.c.
 
 
◆ list_head()
- Parameters
- 
  
  
- Returns
- head of the list
Gets the head of the list. 
Definition at line 422 of file list.c.
 
 
◆ list_init()
- Parameters
- 
  
    | list | a List |  | compare | function to compare item data |  | free | function to free item data or NULL |  | pool | a user-defined memory pool for creating/destroying ListItems or NULL |  
 
Initializes a List. 
Definition at line 48 of file list.c.
 
 
◆ list_insert_sorted()
- Parameters
- 
  
    | list | a List |  | data | data to insert |  
 
- Returns
- a new ListItem
Inserts data into list using the associated compare function to determine its position. 
Definition at line 228 of file list.c.
 
 
◆ list_item_free_data()
      
        
          | void list_item_free_data | ( | const List * | list, | 
        
          |  |  | ListItem * | item | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
  
Sets the associated list item data to NULL and frees its memory. 
Definition at line 454 of file list.c.
 
 
◆ list_new()
- Parameters
- 
  
    | compare | function to compare item data |  | free | function to free item data or NULL |  | pool | a user-defined memory pool for creating/destroying ListItems or NULL |  
 
- Returns
- a new List
Creates a new List. 
Definition at line 30 of file list.c.
 
 
◆ list_pop()
      
        
          | void * list_pop | ( | List * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- list item data
Removes first element from list and returns its associated data. 
Definition at line 322 of file list.c.
 
 
◆ list_prepend()
- Parameters
- 
  
    | list | a List |  | data | data to prepend |  
 
- Returns
- a new ListItem
Prepends data to the list. 
Definition at line 163 of file list.c.
 
 
◆ list_remove()
- Parameters
- 
  
  
Removes a list item from the list. 
Definition at line 285 of file list.c.
 
 
◆ list_remove_by_data()
      
        
          | void list_remove_by_data | ( | List * | list, | 
        
          |  |  | void * | data, | 
        
          |  |  | bool | remove_all | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | list | a List |  | data | data |  | remove_all | true to remove all items with associated data |  
 
Removes first list item (or all items) with associated data from the list. 
Definition at line 298 of file list.c.
 
 
◆ list_tail()
- Parameters
- 
  
  
- Returns
- tail of the list
Gets the tail of the list. 
Definition at line 430 of file list.c.