AddElement() behaviour

Everything else that doesn't fall into one of the other PB categories.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: AddElement() behaviour

Post by DarkDragon »

PureBasic's linked lists are doubly linked with a pointer to the last and first element. See the SDK folder:

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_List has direct pointers to first and last element (and current) and each element knows previous and next.

PB_ListPosition is for Push/PopListPosition()
bye,
Daniel
Post Reply