Fangbeast, thank you.
I must confess that I did not explicitly search for the term, but only looked in the List library command list. But I see now that SortList is also mentioned there. So, as is often the case, the "problem" is clearly the user sitting in front of the screen.
I'll have a look at it today to see if SortStructuredList() can do the job. The peculiarity is that you don't have to sort by a single field, but by the following scheme:
Field A -> Identifier of the entry
Field B -> Identifier ID of an entry to be referenced (can also be empty).
Example:
Code: Select all
A: 0 B: -
A: 1 B: 4
A: 2 B: 3
A: 3 B: 1
A: 4 B: -
Should look sorted like this:
Code: Select all
A: 0 B: -
A: 4 B: -
A: 1 B: 4
A: 3 B: 1
A: 2 B: 3
(in the real case the numbers are integer addresses, so much bigger numbers)
The logic now is to sort everything so that all entries that reference another entry are *after* the referenced element in the list. And there can be references to references to references to references.... etc., i.e. nested references.
I'll create an updated example and try to implement the sorting based on it.
The example in the first post I had only kept so simple because I did not have the Sort commands for lists in mind at the time. This "superficiality" is the price I have to pay, because due to my time management I can only work with Purebasic and projects program in a very fragmented way. The rest of the time I have completely different things in my head. I know this already, that's why I'm only moderately embarrassed by my posts of this kind. LOL
Edit:
This is the example code to get close to the real use case. I don't think you can get there with SortStructuredList() alone, but as I said, I'll take a closer look today.
Code: Select all
Structure MyStruct
Entry.i
RefEntry.i
EndStructure
NewList StructList.MyStruct()
AddElement(StructList()) : StructList()\Entry = 1
AddElement(StructList()) : StructList()\Entry = 2 : StructList()\RefEntry =3
AddElement(StructList()) : StructList()\Entry = 3 : StructList()\RefEntry =6
AddElement(StructList()) : StructList()\Entry = 4
AddElement(StructList()) : StructList()\Entry = 5 : StructList()\RefEntry =2
AddElement(StructList()) : StructList()\Entry = 6
SortStructuredList(StructList(), #PB_Sort_Ascending, OffsetOf(MyStruct\RefEntry), TypeOf(MyStruct\RefEntry))
ForEach StructList()
Debug "Entry: " + Str(StructList()\Entry) + " - Ref to: " + Str(StructList()\RefEntry)
Next