Dawn/src/util/list.h
2021-04-22 13:55:34 +10:00

77 lines
2.3 KiB
C

// Copyright (c) 2021 Dominic Msters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
/**
* Creates a new linked list
* @return Pointer to a new linked list.
*/
list_t * listCreate();
/**
* Adds data to a linked list
*
* @param list* Pointer to a previously created linked list
* @param data* Pointer to your data
* @return A pointer to the new entry in the linked list that was created
*/
listentry_t * listAdd(list_t *list, void *data);
/**
* Internal function
*/
void listAddEntry(list_t *list, listentry_t *entry);
/**
* Remove data from a linked list.
*
* @param list Pointer to a previously created linked list.
* @param data* Pointer to your data.
*/
void listRemove(list_t *list, void *data);
/**
* Remove a list entry from the linked list.
*
* @param list* Pointer to a previously created linked list.
* @param entry* Pointer to the entry within the linked list.
* @param freeData If true the data of the listentry_t will be free()'d
*/
void listRemoveEntry(list_t *list, listentry_t *entry, bool freeData);
/**
* Returns the entry at a given index. This method is costly.
* @param list* Pointer to a previously created linked list
* @param index Index of element within the linked list to remove
* @return The entry at the index or NULL if outside the bounds.
*/
listentry_t * listGetByIndex(list_t *list, uint32_t index);
/**
* Returns the index of data within the linked list. This method is costly.
*
* @param list* Pointer to a previously created linked list
* @param data* Pointer to your data.
* @return The index within the list the entry is in, or -1 if not found.
*/
uint32_t listGetIndex(list_t *list, void* data);
/**
* Returns the index of an entry within the linked list. This method is costly.
*
* @param list* Pointer to a previously created linked list
* @param entry* Pointer to the entry within the linked list.
* @return The index within the list the entry is in, or -1 if not found.
*/
uint32_t listGetEntryIndex(list_t *list, listentry_t *entry);
/**
* Dispose a previously created link list.
* @param list* Pointer to a previously created linked list
* @param freeData If true the data within each listentry_t will be free()'d
*/
void listDispose(list_t *list, bool freeData);