osurs  0.0.1
Data Structures | Functions
arraylist.h File Reference

Arraylist data structure. More...

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

Go to the source code of this file.

Data Structures

struct  ArrayList
 Arraylist. More...
 

Functions

void array_list_init (ArrayList *list)
 Initialize an ArrayList structure. More...
 
ArrayListarray_list_create ()
 Create a new ArrayList structure. More...
 
void array_list_add (ArrayList *list, void *element)
 Add an element to the end of an ArrayList. More...
 
void array_list_add_at (ArrayList *list, int index, void *element)
 Add an element to an ArrayList at a specific index. More...
 
void * array_list_get (ArrayList *list, int index)
 Get an element from an ArrayList. More...
 
void array_list_free (ArrayList *list)
 Free an ArrayList structure. More...
 

Detailed Description

Arraylist data structure.

This file defines an ArrayList data structure, which is a dynamic array that can hold a variable number of elements.

Date
2022-12-21
Author
Merlin Unterfinger

Function Documentation

◆ array_list_add()

void array_list_add ( ArrayList list,
void *  element 
)

Add an element to the end of an ArrayList.

This function adds an element to the end of an ArrayList. If the list's current capacity is not large enough to hold the new element, the capacity is increased to accommodate it.

Parameters
listThe ArrayList to which the element will be added.
elementThe element to be added to the list.

◆ array_list_add_at()

void array_list_add_at ( ArrayList list,
int  index,
void *  element 
)

Add an element to an ArrayList at a specific index.

This function adds an element to an ArrayList at a specific index. If the list's current capacity is not large enough to hold the new element, the capacity is increased to accommodate it. If the index is greater than the current size of the list, the element is added to the end of the list.

Parameters
listThe ArrayList to which the element will be added.
indexThe index at which the element will be inserted.
elementThe element to be added to the list.

◆ array_list_create()

ArrayList* array_list_create ( )

Create a new ArrayList structure.

This function creates a new ArrayList structure and returns a pointer to it. The new structure is initialized with its elements array set to NULL, its capacity set to 0, and its size set to 0.

Returns
A pointer to the new ArrayList structure.

◆ array_list_free()

void array_list_free ( ArrayList list)

Free an ArrayList structure.

This function frees an ArrayList structure, including the elements array and the structure itself.

Parameters
listThe ArrayList structure to be freed.

◆ array_list_get()

void* array_list_get ( ArrayList list,
int  index 
)

Get an element from an ArrayList.

This function retrieves an element from an ArrayList at a specific index. If the index is out of range (less than 0 or greater than or equal to the list's size), the function returns NULL.

Parameters
listThe ArrayList from which the element will be retrieved.
indexThe index of the element to be retrieved.
Returns
The element at the specified index, or NULL if the index is out of range.

◆ array_list_init()

void array_list_init ( ArrayList list)

Initialize an ArrayList structure.

This function initializes an ArrayList structure by setting its elements array to NULL, its capacity to 0, and its size to 0.

Parameters
listThe ArrayList structure to be initialized.