Re: AddElement() behaviour
Posted: Mon Apr 01, 2024 8:31 pm
PureBasic's linked lists are doubly linked with a pointer to the last and first element. See the SDK folder:
PB_List has direct pointers to first and last element (and current) and each element knows previous and next.
PB_ListPosition is for Push/PopListPosition()
Code: Select all
typedef struct PB_ListHeader
{
struct PB_ListHeader *Next;
struct PB_ListHeader *Previous;
} PB_ListHeader;
typedef struct PB_ListPosition
{
struct PB_ListPosition *Next;
PB_ListHeader *Element;
} PB_ListPosition;
struct PB_ListObject;
typedef struct PB_List
{
PB_ListHeader *First;
PB_ListHeader *Last;
PB_ListHeader *Current; // Don't move it, as it is used internally by the compiler
PB_ListHeader **CurrentVariable;
integer NbElements;
integer Index;
integer *StructureMap;
// Every List has its private allocator, so we can call ClearAll() for a fast ClearList()
// Also this way Lists in separate threads work without a lock for allocation
PB_BlockAlloc *Allocator;
// see PushListPosition.c
PB_ListPosition *PositionStack;
struct PB_ListObject *Object;
integer ElementSize; // moved here for better alignment on 64-bit
int ElementType;
char IsIndexInvalid;
char IsDynamic;
char IsDynamicObject;
}
PB_List;
PB_ListPosition is for Push/PopListPosition()