Why the LinkedList-system works with two different pointers?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Why the LinkedList-system works with two different pointers?

Post by Lebostein »

Hi (sorry for my english),

in PB-helpfile I can only read about "pointer to the element". But in PB "pointer to the element" is not "pointer to the element". The commands ChangeCurrentElement() and SwapElements() use the "pointer to the data of the element" and all other commands return the "pointer to the element". This information is very fundamental to use LinkedLists without problems. Look at my abstract:

Code: Select all

Follow commands returns the "ElementPointer":
------------------------------------------------

*ElementPointer = AddElement(linkedlist())
*ElementPointer = FirstElement(linkedlist())
*ElementPointer = InsertElement(linkedlist())
*ElementPointer = LastElement(linkedlist())
*ElementPointer = NextElement(linkedlist())
*ElementPointer = PreviousElement(linkedlist())


Follow commands use the "ElementDataPointer"
------------------------------------------------

ChangeCurrentElement(linkedlist(), *ElementDataPointer)
SwapElements(linkedlist(), *ElementDataPointer, *ElementDataPointer)


How can I get the "ElementDataPointer"?
------------------------------------------------

*ElementDataPointer = *ElementPointer + 8      (from ElementPointer)
*ElementDataPointer = @linkedlist()            (or from current element)

-8 | Pointer to next element (= *ElementPointer)
-4 | Pointer to previous element
 0 | Begin of data in the element (= *ElementDataPointer )
...| .... and more data

Solution 1) Where you need an *ElementPointer in PB? Nowhere! Please change the behaviour for Add.., First..., Insert..,Last...,Next... and PreviousElement() to return the *ElementDataPointer to eliminate unexpected problems
Solution 2) Or the easy way: update the helpfile and be accurate with the description "pointer to the element". Characterise the construction of an element detailed.