Singly-linked list.  
More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "slist.h"
Go to the source code of this file.
|  | 
| SList * | slist_new (CompareFunc compare, FreeFunc free, Pool *pool) | 
|  | 
| void | slist_init (SList *list, CompareFunc compare, FreeFunc free, Pool *pool) | 
|  | 
| void | slist_free (SList *list) | 
|  | 
| void | slist_destroy (SList *list) | 
|  | 
| SListItem * | slist_append (SList *list, void *data) | 
|  | 
| SListItem * | slist_prepend (SList *list, void *data) | 
|  | 
| SListItem * | slist_insert_sorted (SList *list, void *data) | 
|  | 
| void | slist_remove (SList *list, SListItem *item) | 
|  | 
| void | slist_remove_by_data (SList *list, void *data, bool remove_all) | 
|  | 
| void * | slist_pop (SList *list) | 
|  | 
| bool | slist_contains (const SList *list, const void *data) | 
|  | 
| void | slist_clear (SList *list) | 
|  | 
| SListItem * | slist_find (const SList *list, SListItem *offset, void const *data) | 
|  | 
| size_t | slist_count (const SList *list) | 
|  | 
| SListItem * | slist_head (const SList *list) | 
|  | 
| bool | slist_empty (const SList *list) | 
|  | 
| void | slist_item_free_data (const SList *list, SListItem *item) | 
|  | 
◆ slist_append()
- Parameters
- 
  
    | list | a SList |  | data | data to append |  
 
- Returns
- a new SListItem
Appends data to the list. 
Definition at line 133 of file slist.c.
 
 
◆ slist_clear()
      
        
          | void slist_clear | ( | SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
Clears a list. 
Definition at line 390 of file slist.c.
 
 
◆ slist_contains()
      
        
          | bool slist_contains | ( | const SList * | list, | 
        
          |  |  | const void * | data | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | list | a SList |  | data | data to search |  
 
- Returns
- true if data exists in list
Tests if a list contains the specified data. 
Definition at line 381 of file slist.c.
 
 
◆ slist_count()
      
        
          | size_t slist_count | ( | const SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- number of items
Gets the number of items. 
Definition at line 410 of file slist.c.
 
 
◆ slist_destroy()
      
        
          | void slist_destroy | ( | SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
Frees all items in the list and the list pointer. 
Definition at line 98 of file slist.c.
 
 
◆ slist_empty()
      
        
          | bool slist_empty | ( | const SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- true if list is empty
Checks if a list is empty. 
Definition at line 426 of file slist.c.
 
 
◆ slist_find()
- Parameters
- 
  
    | list | a SList |  | offset | position to start search from |  | data | data to search |  
 
- Returns
- found SListItem or NULL
Searches for an element in the list. 
Definition at line 402 of file slist.c.
 
 
◆ slist_free()
      
        
          | void slist_free | ( | SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
Frees all items in the list without freeing the list pointer. 
Definition at line 81 of file slist.c.
 
 
◆ slist_head()
- Parameters
- 
  
  
- Returns
- head of the list
Gets the head of the list. 
Definition at line 418 of file slist.c.
 
 
◆ slist_init()
- Parameters
- 
  
    | list | a SList |  | compare | function to compare item data |  | free | function to free item data OR NULL |  | pool | a user-defined memory pool for creating/destroying SListItems or NULL |  
 
Initializes a new SList. 
Definition at line 48 of file slist.c.
 
 
◆ slist_insert_sorted()
- Parameters
- 
  
    | list | a List |  | data | data to insert |  
 
- Returns
- a new ListItem
Inserts data into the list using the associated compare function to determine its position. 
Definition at line 219 of file slist.c.
 
 
◆ slist_item_free_data()
- Parameters
- 
  
  
Sets the associated list item to NULL and frees memory. 
Definition at line 434 of file slist.c.
 
 
◆ slist_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 SListItems or NULL |  
 
- Returns
- a new SList
Creates a new SList. 
Definition at line 30 of file slist.c.
 
 
◆ slist_pop()
      
        
          | void * slist_pop | ( | SList * | list | ) |  | 
      
 
- Parameters
- 
  
  
- Returns
- list item data
Removes first element from list and returns data. 
Definition at line 325 of file slist.c.
 
 
◆ slist_prepend()
- Parameters
- 
  
    | list | a SList |  | data | data to prepend |  
 
- Returns
- a new SListItem
Prepends data to the list. 
Definition at line 162 of file slist.c.
 
 
◆ slist_remove()
- Parameters
- 
  
  
Removes a list item from the list. 
Definition at line 254 of file slist.c.
 
 
◆ slist_remove_by_data()
      
        
          | void slist_remove_by_data | ( | SList * | list, | 
        
          |  |  | void * | data, | 
        
          |  |  | bool | remove_all | 
        
          |  | ) |  |  | 
      
 
- Parameters
- 
  
    | list | a SList |  | 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 289 of file slist.c.