Linked Lists are currently somewhat like treeview-structure that can store string-values and LL-Elements don't inherit structure of previous elements,
I imagine lists different, so here some pseudo-code how to use:
Type myUDT
A as Long
B as Dword
C as String
End Type
[Dim] NewList myList() as myUDT
[Local] NewList myList() as myUDT
' create an empty new list, has zero elements now
' could also do just: NewList someOtherList() as Long
All list-elements of this Typed-List should now have a 'myUDT'-structure, so every list-element has now A,B and C or whatever the type says.
I think it would enhance the use of objects with similar properties that can be stored in a list, where you currently use Arrays for that always have to be re-dimensioned if one elements gets added or redimensioned and re-ordered if an element gets removed.
There has to be an internal pointer to the currently active element of the list and a few commands like:
AddElement myList()
' will add one element to list myList() and this one is now the currently active one
with myList()
.A = 1
.B = 2
.C = "hello"
end with
AddElement myList()
' add another element to list myList() and this one is now the currently active one
myList().A = 2
myList().B = 1
myList().C = "world"
' GetElementCount myList() should return 2 now...
Now run through that list like this:
ResetList myList()
' set the pointer to 0 (before first element)
' so there's no currently active element
While IsNextElement myList()
' set pointer in myList() to next element
' do something with that (now current) element
' like
Print myList().C
Wend
' now pointer is at last element of myList()...
if IsPreviousElement myList() then
' should set the Pointer to previous element or return False/0 if not exists
my_A_Value = myList().A
myList().C = "good bye world"
' refers all to current element of myList()
else
' there's no previous element...
endif
additional needs:
DeleteElement myList() ' kill the current element, (if one)
' active element is now the previous one or zero
ClearList myList() ' nothing to explain...
myCount = GetElementCount myList() ' return total of elements in myList()
and perhaps some indexing to select a certain element:
myCurrentElementIndex = GetElementIndex myList()
' returns Index of current element
' or 0 if pointer is before list (after resetting) or if list is empty
' so 0 means there's no current element
if SelectElement myList(), 25 then
' make element 25 the current one of myList()
else
' element 25 does not exist in myList()
endif
' so this
if SelectElement myList(), GetElementCount myList()
' will select the last element of myList()
do
' something with current element
loop until not isPreviousElement myList()
'goes backward through list
endif
"TypedList" would be a very small module, could also be built-in to core-engine, I think I would use it together with FILE-module if FILE would provide some built-in File-Type (Filename, FileAtrribute etc.) so can easy read-in directories and I will use together with TBGL anyway to store a lot of different objects like sprites, triangles, vertices, meshes etc. and use it to loop through those object-lists mainly.
Could also provide some sorting methods f.e.:
SortList myList().C, %SortDescending
SortList myList().A, %SortAscending
Bookmarks