looking for a smart approach to "sort" an array

Tiemo Hollmann TB toolbook at kestner.de
Fri May 5 11:30:00 CEST 2017


Hello,

I have a list field of words and a correspondent array with the words of the
field as the keys plus some data per key. I can store the array in a file,
read it later from file and rebuild the list of words from the keys of the
array. Up to now, I had this list of words alphabetically sorted. So it was
easy, when reloading the array to sort the list always alphabetically to
refresh the visible list in the field.

The user can also create a custom sequence of the words in the field by drag
and drop the lines in individual order. Now I am looking for a smart
approach to keep the same sort order in the correspondent array. I need the
custom sort order of the words in case I reload the array later from file to
get the same sequence of words as the user has sorted them, after extracting
the words from the array. The key of the array has to keep the words from
the list for accessing the data in the array.

As far as I see it, I have to add an additional item to the array data,
storing the sort sequence of the keys, while the user creates his custom
sequence of the words in the list field and keeping this number always
synchronous to the line number of the fields list. So I could use this "sort
sequence number" from the array to rebuild the same sort of the words when
extracting the words from the array.

Would this be the best approach to keep the sort sequence of the words
stored with the array, or do you see an easier more straight forward
approach to keep the array "synchronous sorted" which I don't see right now?

Thanks for your input

Tiemo

 

 

 



More information about the use-livecode mailing list