libamxc  1.10.3
C Generic Data Containers
amxc_llist.c File Reference

Ambiorix linked list API implementation. More...

#include <stdlib.h>
#include <amxc/amxc_llist.h>
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

static int amxc_llist_sort_internal (amxc_llist_t *const llist, amxc_llist_it_cmp_t cmp)
 
int amxc_llist_new (amxc_llist_t **llist)
 Allocates a linked list. More...
 
void amxc_llist_delete (amxc_llist_t **llist, amxc_llist_it_delete_t func)
 Frees the previously allocated linked list. More...
 
int amxc_llist_init (amxc_llist_t *const llist)
 Initializes a linked list. More...
 
void amxc_llist_clean (amxc_llist_t *const llist, amxc_llist_it_delete_t func)
 Removes all items from the linked list. More...
 
int amxc_llist_move (amxc_llist_t *const dest, amxc_llist_t *const src)
 Moves all items from one linked list to another linked list. More...
 
size_t amxc_llist_size (const amxc_llist_t *const llist)
 Calculates the size of the linked list. More...
 
bool amxc_llist_is_empty (const amxc_llist_t *const llist)
 Checks that the linked list is empty. More...
 
int amxc_llist_append (amxc_llist_t *const llist, amxc_llist_it_t *const it)
 Adds an item to the end of the linked list. More...
 
int amxc_llist_prepend (amxc_llist_t *const llist, amxc_llist_it_t *const it)
 Adds an item to the beginning of the linked list. More...
 
amxc_llist_it_tamxc_llist_get_at (const amxc_llist_t *const llist, const unsigned int index)
 Gets an item at a certain position of the linked list. More...
 
int amxc_llist_set_at (amxc_llist_t *const llist, const unsigned int index, amxc_llist_it_t *const it)
 Inserts an item at a certain position. More...
 
int amxc_llist_sort (amxc_llist_t *const llist, amxc_llist_it_cmp_t cmp)
 Sorts a linked list. More...
 

Detailed Description

Ambiorix linked list API implementation.

Definition in file amxc_llist.c.

Function Documentation

◆ amxc_llist_sort_internal()

static int amxc_llist_sort_internal ( amxc_llist_t *const  llist,
amxc_llist_it_cmp_t  cmp 
)
static

Definition at line 66 of file amxc_llist.c.

67  {
68  int retval = 0;
69  bool swapped = false;
70 
71  do {
73  swapped = false;
74 
75  while(it != NULL && it->next != NULL) {
76  if(cmp(it, it->next) > 0) {
78  swapped = true;
79  } else {
80  it = it->next;
81  }
82  }
83  } while(swapped);
84 
85  return retval;
86 }
int amxc_llist_it_swap(amxc_llist_it_t *it1, amxc_llist_it_t *it2)
Swaps two linked list iterators.
AMXC_INLINE amxc_llist_it_t * amxc_llist_get_first(const amxc_llist_t *const llist)
Gets the first item of the linked list.
Definition: amxc_llist.h:713
amxc_htable_it_t * next
Definition: amxc_htable.h:141
The linked list iterator structure.
Definition: amxc_llist.h:215
static amxc_htable_it_t it[2000]
static amxc_llist_t * llist