no-OS
Classes | Typedefs | Enumerations | Functions
list.h File Reference

List library header. More...

#include <stdint.h>
#include <stdbool.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  list_desc
 Structure storing the list and function wrapper for usual list types. More...
 

Typedefs

typedef int32_t(* f_cmp) (void *data1, void *data2)
 Prototype of the compare function. More...
 
Generic functions

Each function interacting with the list have one of the following formats.
Aditionaly they may have one more parametere for specific functionalities.
In the Iterator functions, the list reference is replaced by the iterator's one.

typedef int32_t(* f_add) (struct list_desc *list_desc, void *data)
 Add an element in the list. More...
 
typedef int32_t(* f_edit) (struct list_desc *list_desc, void *new_data)
 Edit an element in the list. The content is replaced by new_data. More...
 
typedef int32_t(* f_read) (struct list_desc *list_desc, void **data)
 Read an element from the list. More...
 
typedef int32_t(* f_get) (struct list_desc *list_desc, void **data)
 Read and remove an element from the list. More...
 

Enumerations

enum  adapter_type {
  LIST_DEFAULT,
  LIST_QUEUE,
  LIST_STACK,
  LIST_PRIORITY_LIST
}
 Selects functionalities for functions in list_desc. More...
 

Functions

int32_t list_init (struct list_desc **list_desc, enum adapter_type type, f_cmp comparator)
 
int32_t list_remove (struct list_desc *list_desc)
 
int32_t list_get_size (struct list_desc *list_desc, uint32_t *out_size)
 
Iterator functions

An iterator is used to iterate through the list. For a list, any number of iterators can be created. All must be removed before removing a list.

int32_t iterator_init (struct iterator **iter, struct list_desc *list_desc, bool start)
 
int32_t iterator_remove (struct iterator *iter)
 
int32_t iterator_move (struct iterator *iter, int32_t steps)
 
int32_t iterator_move_to_idx (struct iterator *iter, int32_t idx)
 
int32_t iterator_find (struct iterator *iter, void *cmp_data)
 
int32_t iterator_insert (struct iterator *iter, void *data, bool after)
 
int32_t iterator_edit (struct iterator *iter, void *new_data)
 
int32_t iterator_read (struct iterator *iter, void **data)
 
int32_t iterator_get (struct iterator *iter, void **data)
 
Operations on the ends of the list

These functions will operate on the first or last element of the list

int32_t list_add_first (struct list_desc *list_desc, void *data)
 
int32_t list_edit_first (struct list_desc *list_desc, void *new_data)
 
int32_t list_read_first (struct list_desc *list_desc, void **data)
 
int32_t list_get_first (struct list_desc *list_desc, void **data)
 
int32_t list_add_last (struct list_desc *list_desc, void *data)
 
int32_t list_edit_last (struct list_desc *list_desc, void *new_data)
 
int32_t list_read_last (struct list_desc *list_desc, void **data)
 
int32_t list_get_last (struct list_desc *list_desc, void **data)
 
Operations by index

These functions use an index to identify the element in the list.

int32_t list_add_idx (struct list_desc *list_desc, void *data, uint32_t idx)
 
int32_t list_edit_idx (struct list_desc *list_desc, void *new_data, uint32_t idx)
 
int32_t list_read_idx (struct list_desc *list_desc, void **data, uint32_t idx)
 
int32_t list_get_idx (struct list_desc *list_desc, void **data, uint32_t idx)
 
Operations by comparation

These functions use the specified f_cmp at list_init to identify the element this will operate on.

int32_t list_add_find (struct list_desc *list_desc, void *data)
 
int32_t list_edit_find (struct list_desc *list_desc, void *new_data, void *cmp_data)
 
int32_t list_read_find (struct list_desc *list_desc, void **data, void *cmp_data)
 
int32_t list_get_find (struct list_desc *list_desc, void **data, void *cmp_data)
 

Detailed Description

List library header.

Author
Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Library description

This library handles double linked lists and it expose inseart, read, get and delete functions.
It also can be accesed using it member functions which wrapp function for usual list types.

Sample code

// -- Use a generic list
struct list_desc *list1;
struct iterator *it;
uint32_t a;
// Create list list1
// Add items to the list
list_add_last(list1, 1);
list_add_last(list1, 2);
list_add_last(list1, 3);
// Here the list will be: 1 -> 2 - > 3
list_read_last(list1, &a);
printf("Last: %d\n", a);
// 3 will be printed
// Create an iterator on the end of the list
iterator_init(&it, list1, 0);
// Move the iterator backword with one position
iterator_move(it, -1);
// Read the data at the current position
iterator_read(it, &a);
printf("Current: %d\n", a);
// 2 will be printed
list_remove(list1);
// -- Use a popular list
struct list_desc *stack;
// Create a FIFO list
// Put elements in the list
stack->push(stack, 1);
stack->push(stack, 2);
stack->push(stack, 3);
// Read from the stack
stack->pop(stack, &a);
printf("Last: %d\n", a);
// 3 will be printed
list_remove(stack);

Typedef Documentation

◆ f_add

typedef int32_t(* f_add) (struct list_desc *list_desc, void *data)

Add an element in the list.

The element of the list is created and the data field is stored in it.

Parameters
list_desc- Reference to the list. Created by list_init
data- Data to store in a list element
Returns

◆ f_cmp

typedef int32_t(* f_cmp) (void *data1, void *data2)

Prototype of the compare function.

The function used to compare the elements of the liste when doing operations on an ordered list.

Parameters
data1- First element to be compared
data2- Second element to be compared
Returns
  • -1 - If data1 < data2
  • 0 - If data1 == data2
  • 1 - If data1 > data2

◆ f_edit

typedef int32_t(* f_edit) (struct list_desc *list_desc, void *new_data)

Edit an element in the list. The content is replaced by new_data.

Parameters
list_desc- Reference to the list. Created by list_init .
new_data- New data to replace the old one
Returns

◆ f_get

typedef int32_t(* f_get) (struct list_desc *list_desc, void **data)

Read and remove an element from the list.

Parameters
list_desc- Reference to the list. Created by list_init
result- If not null, result is filled with:
data- Content of the list element, NULL if some error occur.
Returns

◆ f_read

typedef int32_t(* f_read) (struct list_desc *list_desc, void **data)

Read an element from the list.

Parameters
list_desc- Reference to the list. Created by list_init
result- If not null, result is filled with:
data- Content of the list element, NULL if some error occur.
Returns

Note
If the content of an element can be 0 then the result must be checked to see if the functions has succeded

Enumeration Type Documentation

◆ adapter_type

Selects functionalities for functions in list_desc.

Enumerator
LIST_DEFAULT 

Default type is LIST_STACK

LIST_QUEUE 

Functions for a FIFO list (First-in first-out). Elements are inserted in one end and extracted from the other end.

  • Push: Insert element
  • Pop: Get next element (Read and remove)
  • Top_next: Read next element
  • Back: Read first element
  • Swap: Edit the content of the next element
LIST_STACK 

Functions for a LIFO list (Last-in first-out). Elements are inserted and extracted only from the same end.

  • Push: Insert element
  • Pop: Get top element (Read and remove)
  • Top_next: Read top element
  • Back: Read bottom element
  • Swap: Edit the content of the top element
LIST_PRIORITY_LIST 

Functions for ordered list. The order of element is determinated usinge the f_cmp.

  • Push: Insert element
  • Pop: Get lowest element (Read and remove)
  • Top_next: Read lowest element
  • Back: Read the biggest element
  • Swap: Edit the lowest element

Function Documentation

◆ iterator_edit()

int32_t iterator_edit ( struct iterator *  iter,
void *  new_data 
)

◆ iterator_find()

int32_t iterator_find ( struct iterator *  iter,
void *  cmp_data 
)
Here is the caller graph for this function:

◆ iterator_get()

int32_t iterator_get ( struct iterator *  iter,
void **  data 
)

◆ iterator_init()

int32_t iterator_init ( struct iterator **  iter,
struct list_desc list_desc,
bool  start 
)

◆ iterator_insert()

int32_t iterator_insert ( struct iterator *  iter,
void *  data,
bool  after 
)

◆ iterator_move()

int32_t iterator_move ( struct iterator *  iter,
int32_t  steps 
)
Here is the caller graph for this function:

◆ iterator_move_to_idx()

int32_t iterator_move_to_idx ( struct iterator *  iter,
int32_t  idx 
)
Here is the caller graph for this function:

◆ iterator_read()

int32_t iterator_read ( struct iterator *  iter,
void **  data 
)
Here is the caller graph for this function:

◆ iterator_remove()

int32_t iterator_remove ( struct iterator *  iter)
Here is the caller graph for this function:

◆ list_add_find()

int32_t list_add_find ( struct list_desc list_desc,
void *  data 
)

◆ list_add_first()

int32_t list_add_first ( struct list_desc list_desc,
void *  data 
)

◆ list_add_idx()

int32_t list_add_idx ( struct list_desc list_desc,
void *  data,
uint32_t  idx 
)

◆ list_add_last()

int32_t list_add_last ( struct list_desc list_desc,
void *  data 
)
Here is the caller graph for this function:

◆ list_edit_find()

int32_t list_edit_find ( struct list_desc list_desc,
void *  new_data,
void *  cmp_data 
)

◆ list_edit_first()

int32_t list_edit_first ( struct list_desc list_desc,
void *  new_data 
)

◆ list_edit_idx()

int32_t list_edit_idx ( struct list_desc list_desc,
void *  new_data,
uint32_t  idx 
)

◆ list_edit_last()

int32_t list_edit_last ( struct list_desc list_desc,
void *  new_data 
)

◆ list_get_find()

int32_t list_get_find ( struct list_desc list_desc,
void **  data,
void *  cmp_data 
)
Here is the caller graph for this function:

◆ list_get_first()

int32_t list_get_first ( struct list_desc list_desc,
void **  data 
)
Here is the caller graph for this function:

◆ list_get_idx()

int32_t list_get_idx ( struct list_desc list_desc,
void **  data,
uint32_t  idx 
)

◆ list_get_last()

int32_t list_get_last ( struct list_desc list_desc,
void **  data 
)

◆ list_get_size()

int32_t list_get_size ( struct list_desc list_desc,
uint32_t *  out_size 
)

◆ list_init()

int32_t list_init ( struct list_desc **  list_desc,
enum adapter_type  type,
f_cmp  comparator 
)
Here is the caller graph for this function:

◆ list_read_find()

int32_t list_read_find ( struct list_desc list_desc,
void **  data,
void *  cmp_data 
)

◆ list_read_first()

int32_t list_read_first ( struct list_desc list_desc,
void **  data 
)

◆ list_read_idx()

int32_t list_read_idx ( struct list_desc list_desc,
void **  data,
uint32_t  idx 
)

◆ list_read_last()

int32_t list_read_last ( struct list_desc list_desc,
void **  data 
)

◆ list_remove()

int32_t list_remove ( struct list_desc list_desc)
Here is the caller graph for this function:
LIST_DEFAULT
@ LIST_DEFAULT
Definition: list.h:201
list_desc::push
f_add push
Definition: list.h:236
list_add_last
int32_t list_add_last(struct list_desc *list_desc, void *data)
iterator_init
int32_t iterator_init(struct iterator **iter, struct list_desc *list_desc, bool start)
LIST_STACK
@ LIST_STACK
Definition: list.h:221
iterator_read
int32_t iterator_read(struct iterator *iter, void **data)
list_init
int32_t list_init(struct list_desc **list_desc, enum adapter_type type, f_cmp comparator)
list_desc
Structure storing the list and function wrapper for usual list types.
Definition: list.h:234
list_desc::pop
f_get pop
Definition: list.h:238
iterator_remove
int32_t iterator_remove(struct iterator *iter)
iterator_move
int32_t iterator_move(struct iterator *iter, int32_t steps)
list_read_last
int32_t list_read_last(struct list_desc *list_desc, void **data)
NULL
#define NULL
Definition: wrapper.h:64
list_remove
int32_t list_remove(struct list_desc *list_desc)