Loading...
Searching...
No Matches
List.h
Go to the documentation of this file.
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYCORE_LIST_H
#define ZYCORE_LIST_H
#include <Zycore/Allocator.h>
#include <Zycore/Object.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
typedef struct ZyanListNode_
{
struct ZyanListNode_* prev;
struct ZyanListNode_* next;
} ZyanListNode;
typedef struct ZyanList_
{
ZyanAllocator* allocator;
ZyanUSize size;
ZyanUSize element_size;
ZyanMemberProcedure destructor;
ZyanListNode* head;
ZyanListNode* tail;
void* buffer;
ZyanUSize capacity;
ZyanListNode* first_unused;
} ZyanList;
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
#define ZYAN_LIST_INITIALIZER \
{ \
/* allocator */ ZYAN_NULL, \
/* size */ 0, \
/* element_size */ 0, \
/* head */ ZYAN_NULL, \
/* destructor */ ZYAN_NULL, \
/* tail */ ZYAN_NULL, \
/* buffer */ ZYAN_NULL, \
/* capacity */ 0, \
/* first_unused */ ZYAN_NULL \
}
/* ---------------------------------------------------------------------------------------------- */
/* Helper macros */
/* ---------------------------------------------------------------------------------------------- */
#ifdef __cplusplus
#define ZYAN_LIST_GET(type, node) \
(*reinterpret_cast<const type*>(ZyanListGetNodeData(node)))
#else
#define ZYAN_LIST_GET(type, node) \
(*(const type*)ZyanListGetNodeData(node))
#endif
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constructor and destructor */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYAN_NO_LIBC
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList* list, ZyanUSize element_size,
ZyanMemberProcedure destructor);
#endif // ZYAN_NO_LIBC
ZYCORE_EXPORT ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size,
ZyanMemberProcedure destructor, ZyanAllocator* allocator);
ZYCORE_EXPORT ZyanStatus ZyanListInitCustomBuffer(ZyanList* list, ZyanUSize element_size,
ZyanMemberProcedure destructor, void* buffer, ZyanUSize capacity);
ZYCORE_EXPORT ZyanStatus ZyanListDestroy(ZyanList* list);
/* ---------------------------------------------------------------------------------------------- */
/* Duplication */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYAN_NO_LIBC
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListDuplicate(ZyanList* destination,
const ZyanList* source);
#endif // ZYAN_NO_LIBC
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateEx(ZyanList* destination, const ZyanList* source,
ZyanAllocator* allocator);
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateCustomBuffer(ZyanList* destination,
const ZyanList* source, void* buffer, ZyanUSize capacity);
/* ---------------------------------------------------------------------------------------------- */
/* Item access */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanListGetHeadNode(const ZyanList* list, const ZyanListNode** node);
ZYCORE_EXPORT ZyanStatus ZyanListGetTailNode(const ZyanList* list, const ZyanListNode** node);
ZYCORE_EXPORT ZyanStatus ZyanListGetPrevNode(const ZyanListNode** node);
ZYCORE_EXPORT ZyanStatus ZyanListGetNextNode(const ZyanListNode** node);
ZYCORE_EXPORT const void* ZyanListGetNodeData(const ZyanListNode* node);
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode* node, const void** value);
ZYCORE_EXPORT void* ZyanListGetNodeDataMutable(const ZyanListNode* node);
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode* node, void** value);
ZYCORE_EXPORT ZyanStatus ZyanListSetNodeData(const ZyanList* list, const ZyanListNode* node,
const void* value);
/* ---------------------------------------------------------------------------------------------- */
/* Insertion */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanListPushBack(ZyanList* list, const void* item);
ZYCORE_EXPORT ZyanStatus ZyanListPushFront(ZyanList* list, const void* item);
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceBack(ZyanList* list, void** item,
ZyanMemberFunction constructor);
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceFront(ZyanList* list, void** item,
ZyanMemberFunction constructor);
/* ---------------------------------------------------------------------------------------------- */
/* Deletion */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanListPopBack(ZyanList* list);
ZYCORE_EXPORT ZyanStatus ZyanListPopFront(ZyanList* list);
ZYCORE_EXPORT ZyanStatus ZyanListRemove(ZyanList* list, const ZyanListNode* node);
ZYCORE_EXPORT ZyanStatus ZyanListRemoveRange(ZyanList* list, const ZyanListNode* first,
const ZyanListNode* last);
ZYCORE_EXPORT ZyanStatus ZyanListClear(ZyanList* list);
/* ---------------------------------------------------------------------------------------------- */
/* Searching */
/* ---------------------------------------------------------------------------------------------- */
// TODO:
/* ---------------------------------------------------------------------------------------------- */
/* Memory management */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanListResize(ZyanList* list, ZyanUSize size);
ZYCORE_EXPORT ZyanStatus ZyanListResizeEx(ZyanList* list, ZyanUSize size, const void* initializer);
/* ---------------------------------------------------------------------------------------------- */
/* Information */
/* ---------------------------------------------------------------------------------------------- */
ZYCORE_EXPORT ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYCORE_VECTOR_H */
Allocator.h
ZyanAllocator
struct ZyanAllocator_ ZyanAllocator
ZYAN_REQUIRES_LIBC
#define ZYAN_REQUIRES_LIBC
Definition Defines.h:382
ZYCORE_EXPORT
#define ZYCORE_EXPORT
Definition Defines.h:244
ZyanListInitEx
ZYCORE_EXPORT ZyanStatus ZyanListInitEx(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor, ZyanAllocator *allocator)
ZyanListPushFront
ZYCORE_EXPORT ZyanStatus ZyanListPushFront(ZyanList *list, const void *item)
ZyanList
struct ZyanList_ ZyanList
ZyanListDestroy
ZYCORE_EXPORT ZyanStatus ZyanListDestroy(ZyanList *list)
ZyanListGetNodeDataMutableEx
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode *node, void **value)
ZyanListPopBack
ZYCORE_EXPORT ZyanStatus ZyanListPopBack(ZyanList *list)
ZyanListRemove
ZYCORE_EXPORT ZyanStatus ZyanListRemove(ZyanList *list, const ZyanListNode *node)
ZyanListPushBack
ZYCORE_EXPORT ZyanStatus ZyanListPushBack(ZyanList *list, const void *item)
ZyanListEmplaceBack
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceBack(ZyanList *list, void **item, ZyanMemberFunction constructor)
ZyanListNode
struct ZyanListNode_ ZyanListNode
ZyanListEmplaceFront
ZYCORE_EXPORT ZyanStatus ZyanListEmplaceFront(ZyanList *list, void **item, ZyanMemberFunction constructor)
ZyanListInitCustomBuffer
ZYCORE_EXPORT ZyanStatus ZyanListInitCustomBuffer(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor, void *buffer, ZyanUSize capacity)
ZyanListPopFront
ZYCORE_EXPORT ZyanStatus ZyanListPopFront(ZyanList *list)
ZyanListSetNodeData
ZYCORE_EXPORT ZyanStatus ZyanListSetNodeData(const ZyanList *list, const ZyanListNode *node, const void *value)
ZyanListGetTailNode
ZYCORE_EXPORT ZyanStatus ZyanListGetTailNode(const ZyanList *list, const ZyanListNode **node)
ZyanListGetNodeData
ZYCORE_EXPORT const void * ZyanListGetNodeData(const ZyanListNode *node)
ZyanListGetNextNode
ZYCORE_EXPORT ZyanStatus ZyanListGetNextNode(const ZyanListNode **node)
ZyanListDuplicateEx
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateEx(ZyanList *destination, const ZyanList *source, ZyanAllocator *allocator)
ZyanListDuplicate
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListDuplicate(ZyanList *destination, const ZyanList *source)
ZyanListInit
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList *list, ZyanUSize element_size, ZyanMemberProcedure destructor)
ZyanListGetHeadNode
ZYCORE_EXPORT ZyanStatus ZyanListGetHeadNode(const ZyanList *list, const ZyanListNode **node)
ZyanListRemoveRange
ZYCORE_EXPORT ZyanStatus ZyanListRemoveRange(ZyanList *list, const ZyanListNode *first, const ZyanListNode *last)
ZyanListResize
ZYCORE_EXPORT ZyanStatus ZyanListResize(ZyanList *list, ZyanUSize size)
ZyanListDuplicateCustomBuffer
ZYCORE_EXPORT ZyanStatus ZyanListDuplicateCustomBuffer(ZyanList *destination, const ZyanList *source, void *buffer, ZyanUSize capacity)
ZyanListGetPrevNode
ZYCORE_EXPORT ZyanStatus ZyanListGetPrevNode(const ZyanListNode **node)
ZyanListResizeEx
ZYCORE_EXPORT ZyanStatus ZyanListResizeEx(ZyanList *list, ZyanUSize size, const void *initializer)
ZyanListGetSize
ZYCORE_EXPORT ZyanStatus ZyanListGetSize(const ZyanList *list, ZyanUSize *size)
ZyanListClear
ZYCORE_EXPORT ZyanStatus ZyanListClear(ZyanList *list)
ZyanListGetNodeDataEx
ZYCORE_EXPORT ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode *node, const void **value)
ZyanListGetNodeDataMutable
ZYCORE_EXPORT void * ZyanListGetNodeDataMutable(const ZyanListNode *node)
Object.h
ZyanMemberProcedure
void(* ZyanMemberProcedure)(void *object)
Definition Object.h:51
ZyanMemberFunction
ZyanStatus(* ZyanMemberFunction)(void *object)
Definition Object.h:67
Status.h
ZyanStatus
ZyanU32 ZyanStatus
Definition Status.h:48
Types.h
ZyanListNode_
Definition List.h:55
ZyanListNode_::next
struct ZyanListNode_ * next
Definition List.h:63
ZyanListNode_::prev
struct ZyanListNode_ * prev
Definition List.h:59
ZyanList_
Definition List.h:73
ZyanList_::head
ZyanListNode * head
Definition List.h:93
ZyanList_::element_size
ZyanUSize element_size
Definition List.h:85
ZyanList_::destructor
ZyanMemberProcedure destructor
Definition List.h:89
ZyanList_::tail
ZyanListNode * tail
Definition List.h:97
ZyanList_::capacity
ZyanUSize capacity
Definition List.h:109
ZyanList_::buffer
void * buffer
Definition List.h:103
ZyanList_::size
ZyanUSize size
Definition List.h:81
ZyanList_::allocator
ZyanAllocator * allocator
Definition List.h:77
ZyanList_::first_unused
ZyanListNode * first_unused
Definition List.h:124