orca-software
Functions
list.c File Reference
#include <hal.h>
#include <libc.h>
#include <malloc.h>
#include <list.h>

Functions

struct listhf_list_init (void)
 Initializes a list. More...
 
int32_t hf_list_append (struct list *lst, void *item)
 Appends a new node to the end of the list. More...
 
int32_t hf_list_insert (struct list *lst, void *item, int32_t pos)
 Inserts a new node to an arbitrary position in a list. More...
 
int32_t hf_list_remove (struct list *lst, int32_t pos)
 Removes an arbitrary node from a list. More...
 
void * hf_list_get (struct list *lst, int32_t pos)
 Returns the address of the data belonging to a list node. More...
 
int32_t hf_list_set (struct list *lst, void *item, int32_t pos)
 Changes the address of the data belonging to a list node. More...
 
int32_t hf_list_count (struct list *lst)
 Returns the number of nodes in a list. More...
 

Detailed Description

Author
Sergio Johann Filho
Date
January 2016

LICENSE

This source code is licensed under the GNU General Public License, Version 2. See the file 'doc/license/gpl-2.0.txt' for more details.

DESCRIPTION

List manipulation primitives and auxiliary functions. List structures are allocated dynamically at runtime, which makes them very flexible. Memory is allocated / deallocated on demand, so additional memory management penalties are incurred.

Function Documentation

§ hf_list_append()

int32_t hf_list_append ( struct list lst,
void *  item 
)

Appends a new node to the end of the list.

Parameters
lstis a pointer to a list structure.
itemis a pointer to data belonging to the list node.
Returns
0 when successful and -1 otherwise.

§ hf_list_count()

int32_t hf_list_count ( struct list lst)

Returns the number of nodes in a list.

Parameters
lstis a pointer to a list structure.
Returns
The number of elements in the list.

§ hf_list_get()

void* hf_list_get ( struct list lst,
int32_t  pos 
)

Returns the address of the data belonging to a list node.

Parameters
lstis a pointer to a list structure.
posis the n-th element position in the list.
Returns
0 when the element is not found and the address to data otherwise.

§ hf_list_init()

struct list* hf_list_init ( void  )

Initializes a list.

Returns
a pointer to a list structure.

§ hf_list_insert()

int32_t hf_list_insert ( struct list lst,
void *  item,
int32_t  pos 
)

Inserts a new node to an arbitrary position in a list.

Parameters
lstis a pointer to a list structure.
itemis a pointer to data belonging to the list node.
posis the n-th element position in the list.
Returns
0 when successful and -1 otherwise.

§ hf_list_remove()

int32_t hf_list_remove ( struct list lst,
int32_t  pos 
)

Removes an arbitrary node from a list.

Parameters
lstis a pointer to a list structure.
posis the n-th element position in the list.
Returns
0 when successful and -1 otherwise.

§ hf_list_set()

int32_t hf_list_set ( struct list lst,
void *  item,
int32_t  pos 
)

Changes the address of the data belonging to a list node.

Parameters
lstis a pointer to a list structure.
itemis an address to data belonging to the list node.
posis the n-th element position in the list.
Returns
-1 when the element is not found and 0 if the element was updated.