linked_list.h File Reference

Standard singly-linked list. More...

#include <inttypes.h>

Go to the source code of this file.

Data Structures

struct  struct_linked_list_node_t
 A basic implementation of a linked list node. More...
struct  struct_linked_list_t
 A basic implementation of a linked list. More...

Defines

#define _TIFA_LINKED_LIST_H_

Typedefs

typedef struct struct_linked_list_t linked_list_t
 Equivalent to struct struct_linked_list_t.
typedef struct
struct_linked_list_node_t 
linked_list_node_t
 Equivalent to struct struct_linked_list_node_t.

Functions

void init_linked_list (linked_list_t *const list, int(*cmp_func)(const void *const data_a, const void *const data_b))
 Initializes a linked_list_t.
void clear_linked_list (linked_list_t *const list)
 Clears a linked_list_t.
void append_to_linked_list (linked_list_t *const list, void *const data)
 Appends a node in a linked_list_t.
void prepend_to_linked_list (linked_list_t *const list, void *const data)
 Prepends a node in a linked_list_t.
void * pop_linked_list (linked_list_t *const list)
 Deletes the last node of a linked_list_t.
void * push_linked_list (linked_list_t *const list)
 Deletes the first node of a linked_list_t.
void insert_in_linked_list (linked_list_t *const list, void *const data)
 Inserts a node in a linked_list_t.
linked_list_node_tget_node_in_linked_list (linked_list_t *const list, void *const data)
 Gets a node in a linked_list_t.
linked_list_node_tremove_from_linked_list (linked_list_t *const list, void *const data)
 Gets a node in a linked_list_t and removes it from the list.
void remove_node_from_linked_list (linked_list_t *const list, linked_list_node_t *const node)
 Removes a given node from a linked_list_t.
void delete_in_linked_list (linked_list_t *const list, void *const data)
 Finds and deletes a node from a linked_list_t.


Detailed Description

Standard singly-linked list.

Author:
Jerome Milan
Date:
Fri Jun 10 2011
Version:
2011-06-10
Defines generic singly-linked lists and their associated functions.

Definition in file linked_list.h.


Define Documentation

#define _TIFA_LINKED_LIST_H_

Standard include guard.

Definition at line 35 of file linked_list.h.


Function Documentation

void append_to_linked_list ( linked_list_t *const   list,
void *const   data 
)

Appends a node in a linked_list_t.

Appends a node (whose data is given by the pointer data) in the linked list list.

Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the new node's data.

void clear_linked_list ( linked_list_t *const   list  ) 

Clears a linked_list_t.

Clears a linked list list by freeing its nodes.

Warning:
Each node's data field is freed. However, if data is a pointer to a structure containing some other pointers, all the memory may not be freed.
Parameters:
[in] list A pointer to the linked_list_t to clear.

void delete_in_linked_list ( linked_list_t *const   list,
void *const   data 
)

Finds and deletes a node from a linked_list_t.

Deletes the node whose data is given by the pointer data from the linked list list. If the node is not found, the linked list is left unchanged.

Warning:
If a matching node is found, its data field is freed. However, if data is a pointer to a structure containing some other pointers, all the memory may not be freed.
Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the data of the node to delete.

linked_list_node_t* get_node_in_linked_list ( linked_list_t *const   list,
void *const   data 
)

Gets a node in a linked_list_t.

Returns a pointer to a node (whose data is given by the pointer data) from the linked list list.

Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the seeked node data.
Returns:
A pointer to the node with data pointed by data, if such a node exists.

NULL if no matching node is found in the linked list.

void init_linked_list ( linked_list_t *const   list,
int(*)(const void *const data_a, const void *const data_b)  cmp_func 
)

Initializes a linked_list_t.

Initializes a linked list list:

  • Sets its head to NULL.
  • Sets its tail to NULL.
  • Sets its cmp_func to the cmp_func argument.
  • Sets its length to 0.
Parameters:
[in] list A pointer to the linked_list_t to initialize.
[in] cmp_func A pointer to the comparison function.

void insert_in_linked_list ( linked_list_t *const   list,
void *const   data 
)

Inserts a node in a linked_list_t.

Inserts a node (whose data is given by the pointer data) in the linked list list, so that all the previous nodes have data fields pointing to datas less than the new node's data.

Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the new node's data.

void* pop_linked_list ( linked_list_t *const   list  ) 

Deletes the last node of a linked_list_t.

Returns the data of the last node of the linked list list and deletes this node, similar to Perl's pop function.

Parameters:
[in] list A pointer to the linked_list_t.

void prepend_to_linked_list ( linked_list_t *const   list,
void *const   data 
)

Prepends a node in a linked_list_t.

Prepends a node (whose data is given by the pointer data) in the linked list list.

Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the new node's data.

void* push_linked_list ( linked_list_t *const   list  ) 

Deletes the first node of a linked_list_t.

Returns the data of the first node of the linked list list and deletes this node, similar to Perl's push function.

Parameters:
[in] list A pointer to the linked_list_t.

linked_list_node_t* remove_from_linked_list ( linked_list_t *const   list,
void *const   data 
)

Gets a node in a linked_list_t and removes it from the list.

Returns a pointer to a node (whose data is given by the pointer data) from the linked list list and removes this node from the list.

Parameters:
[in] list A pointer to the linked_list_t.
[in] data A pointer to the seeked node data.
Returns:
A pointer to the node with data pointed by data, if such a node exists.

NULL if no matching node is found in the linked list.

void remove_node_from_linked_list ( linked_list_t *const   list,
linked_list_node_t *const   node 
)

Removes a given node from a linked_list_t.

Removes the node whose data is given by the pointer data from the linked list list. If the node is not found, the linked list is left unchanged.

Parameters:
[in] list A pointer to the linked_list_t.
[in] node A pointer to the node to remove from the list.


Generated on Fri Jun 17 11:10:12 2011 for TIFA by Doxygen 1.5.5