clist
A multi-mode C linked list library/implementation
Loading...
Searching...
No Matches
Clist

The main module. Please note that as of now, not all functions have been implemented. Only the documentation for the function prototype is displayed here. More...

Files

file  clist.h
 Provides the function prototypes and the list structures. This header provides the prototypes of the list functions for the source files and provides the node and the list structure.
 
file  clist.c
 Function definitions for clist.hThis file provides function definitions for clist.h.
 

Data Structures

struct  node
 A single node element for the list. More...
 
struct  clist
 A double-way linked list. More...
 

Functions

struct clistclist_init (size_t item_size)
 Create a clist. More...
 
size_t clist_free (struct clist *clist)
 Frees a list. More...
 
void * clist_append (struct clist *clist, const void *item)
 Append an item. More...
 
void * clist_pop (struct clist *clist)
 Pops the last item from a clist. More...
 
size_t clist_length (const struct clist *clist)
 Returns the length of the list. More...
 
void * clist_jump (struct clist *clist, unsigned long index)
 Jump to the given index. More...
 
void * clist_read (const struct clist *clist)
 Return the item on the current index. More...
 
void * clist_write (const struct clist *clist, void *item)
 Replace the item on the current index. More...
 
void * clist_insert (struct clist *clist, void *item, unsigned long index)
 Insert an item. More...
 
void * clist_remove (struct clist *clist, unsigned long index)
 Remove an item. More...
 

Detailed Description

The main module. Please note that as of now, not all functions have been implemented. Only the documentation for the function prototype is displayed here.

Function Documentation

◆ clist_append()

void * clist_append ( struct clist clist,
const void *  item 
)

Append an item.

Append an item at the end of the list while still staying on the current index. clist::list_length is updated accordingly.

Parameters
clistThe list to be operated on. This has to be a modifiable pointer pointing to the list, since we are modifying clist::end. The item will be copied onto the list instead of being linked onto, i.e. using memcpy.
itemA pointer to the item that has to to be appended.
Returns
A pointer to the item on the newly appended node. If failed appending a node at all, returns NULL.

◆ clist_free()

size_t clist_free ( struct clist clist)

Frees a list.

The function frees all memory which was allocated for the list.

Parameters
clistThe pointer to a clist which (including all its items) should be freed.
Returns
The count of items in the list.

◆ clist_init()

struct clist * clist_init ( size_t  item_size)

Create a clist.

This function is used to create and initialize a clist, performing all necessary steps while doing this.

Parameters
item_sizeSpecifies how big one "item" is. An item is a block of data that is defined by you and will be stored on the linked list. No explicit type for an item is required, just provide the size of the item.
Returns
a pointer to the clist that is created, NULL if failed.

◆ clist_insert()

void * clist_insert ( struct clist clist,
void *  item,
unsigned long  index 
)

Insert an item.

On the list, insert an item after the index specified by index. The current index (clist::current) is preserved.

Parameters
clistThe list to be operated on.
itemThe item to insert.
indexThe index after which to insert the item.
Returns
The item if insertion was successful, otherwise NULL.

◆ clist_jump()

void * clist_jump ( struct clist clist,
unsigned long  index 
)

Jump to the given index.

Jumps to the given index and returns the item on that index.

Parameters
clistThe list to be operated on.
indexThe index to jump to.
Returns
The item on that index of the list if succeeded, NULL if failed (possible reasons are out-of-index access etc.).

◆ clist_length()

size_t clist_length ( const struct clist clist)

Returns the length of the list.

Returns clist::list_length.

Parameters
clistThe list to be operated on.
Returns
Returns clist::list_length.

◆ clist_pop()

void * clist_pop ( struct clist clist)

Pops the last item from a clist.

The last item is popped from a clist. clist::list_length is updated accordingly. If clist::current is the last index node, i.e. clist::current will be popped after this function, move one node back.

Parameters
clistThe list to be operated on.
Returns
The item that was popped. If no item was popped because the length of the list was too short, returns NULL.

◆ clist_read()

void * clist_read ( const struct clist clist)

Return the item on the current index.

Returns the item on the current index.

Parameters
clistThe list to be operated on.
Returns
The item on the current index of the list.

◆ clist_remove()

void * clist_remove ( struct clist clist,
unsigned long  index 
)

Remove an item.

Removes the item specified by index. If the current index (clist::current) is to be removed, move one index back. If this is not possible, move one index forward. If neither of both is possible, clist::current is set to NULL.

Parameters
clistThe list to be operated on.
indexThe index which has to be removed.
Returns
The removed item if succeeded, NULL if failed.

◆ clist_write()

void * clist_write ( const struct clist clist,
void *  item 
)

Replace the item on the current index.

Replaces the item on the current index, with item.

Parameters
clistThe list to be operated on.
itemThe item that should replace the item on the current index.
Returns
The item that was previously on the current index.