waitui/library/list/include/waitui/list.h
Rick Barenthin 219812f20e
All checks were successful
continuous-integration/drone/push Build is passing
feat(hashtable): add a hashtable implementation
This is a generic hashtable implementation.

Reviewed-on: #12
PR #12
2022-07-27 19:10:09 +02:00

131 lines
3.9 KiB
C

/**
* @file list.h
* @author rick
* @date 22.07.20
* @brief File for the List implementation
*/
#ifndef WAITUI_LIST_H
#define WAITUI_LIST_H
#include <stdbool.h>
// -----------------------------------------------------------------------------
// Public types
// -----------------------------------------------------------------------------
/**
* @brief Type representing a List node
*/
typedef struct waitui_list_node waitui_list_node;
/**
* @brief Type for element destroy function
*/
typedef void (*waitui_list_element_destroy)(void **element);
/**
* @brief Type representing a List
*/
typedef struct waitui_list waitui_list;
/**
* @brief Type representing a List iterator
*/
typedef struct waitui_list_iter waitui_list_iter;
// -----------------------------------------------------------------------------
// Public functions
// -----------------------------------------------------------------------------
/**
* @brief Create a List
* @param[in] elementDestroyCallback Function to call for element destruction
* @return A pointer to waitui_list or NULL if memory allocation failed
*/
extern waitui_list *
waitui_list_new(waitui_list_element_destroy elementDestroyCallback);
/**
* @brief Destroy a List
* @param[in,out] this The List to destroy
* @note This will free call for every element the elementDestroyCallback
*/
extern void waitui_list_destroy(waitui_list **this);
/**
* @brief Add the element to the end of the List
* @param[in,out] this The List to add the element at the end
* @param[in] element The element to add
* @note This function does steel the pointer to the element
* @retval 1 Ok
* @retval 0 Memory allocation failed
*/
extern int waitui_list_push(waitui_list *this, void *element);
/**
* @brief Remove the element from the end of the List and return it
* @param[in,out] this The List to remove the element from
* @note The caller has to destroy element on its own
* @return The element or NULL if waitui_list is empty
*/
extern void *waitui_list_pop(waitui_list *this);
/**
* @brief Add the element to the beginning of the List
* @param[in,out] this The List to add the element at the beginning
* @param[in] element The element to add
* @note This function does steel the pointer to the element
* @retval 1 Ok
* @retval 0 Memory allocation failed
*/
extern int waitui_list_unshift(waitui_list *this, void *element);
/**
* @brief Remove the element from the beginning of the List and return it
* @param[in,out] this The List to remove the element from
* @note The caller has to destroy element on its own
* @return The element or NULL if waitui_list is empty
*/
extern void *waitui_list_shift(waitui_list *this);
/**
* @brief Return the element from the end of the List, without removing it
* @param[in] this The List to get the last element from
* @warning The caller has not to destroy element on its own
* @return The element or NULL if waitui_list is empty
*/
extern void *waitui_list_peek(waitui_list *this);
/**
* @brief Return the iterator to iterate over the List
* @param[in] this The List to get the iterator for
* @return A pointer to waitui_list_iter or NULL if memory allocation failed
*/
extern waitui_list_iter *waitui_list_getIterator(waitui_list *this);
/**
* @brief Return true if the List iterator has a next element
* @param[in] this The List iterator to test for next element available
* @retval true If the iterator has a next element available
* @retval false If the iterator has no next element available
*/
extern bool waitui_list_iter_hasNext(waitui_list_iter *this);
/**
* @brief Return the next element from the List iterator
* @param[in] this The List iterator to get the next element
* @return The element or NULL if no more elements are available
*/
extern void *waitui_list_iter_next(waitui_list_iter *this);
/**
* @brief Destroy a List iterator
* @param[in,out] this The List iterator to destroy
*/
extern void waitui_list_iter_destroy(waitui_list_iter **this);
#endif//WAITUI_LIST_H