KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
697 stars 230 forks source link

Sort lexicon constructs by value #1959

Open aidygus opened 7 years ago

aidygus commented 7 years ago

While the lexicon allows for a very efficient way of being able to store values against specific keys for quick lookup if you know the key, there are also use cases where being able to query the lowest or highest value to find a key would improve the functionality and speed of scripts dramatically.

A use case I have now is in finding the lowest fscore value in a list of open grid references on an A* search algorithm used for navigating rovers over bodies. Currently options I have are to loop through the whole open set to find the lowest value, or to store grid references in a lexicon where the key is the fscore and store grid references as a list within. This still requires looping through the lexicon keys to find the lowest fscore. A sort function on the Lexicon would allow me to get this lowest value without needing to loop at each iteration.

hvacengi commented 7 years ago

There has been some discussion in the past about implementing a method of sorting that calls a user defined (kerboscript) sorting comparitor function. But that hasn't moved very far, and it doesn't completely fix your issue since the comparison is still implemented in your kerboscript. I'll flag it as an enhancement request.