10-15-2024 02:04 AM
Hi,
I'm having a problem that led me on this topic. You say maps are sorted by key when passed into a for loop. Well, it's something we've based a core algorithm on, and actually it seems its not always the case. Here you can see the problem
I am working with LV20f1 on a linux RT target cRIO 9039.
Of course the exact same code ran on Windows show a properly sorted time array...
I will change my core algo to NOT rely on maps, but i though it was nice to share this with you.
10-15-2024 03:37 AM
@Jonzarwal wrote:I'm having a problem that led me on this topic. You say maps are sorted by key when passed into a for loop. Well, it's something we've based a core algorithm on, and actually it seems its not always the case. Here you can see the problem
They are still sorted. We just don't know (or control) the sorting algorithm.
Logically, we'd assume sequential time, but the sorting is probably done on the binary data. So it might seem illogical to us. Although I'd expect it to be consistent formally the order of maps is not defined.
@Jonzarwal wrote:I will change my core algo to NOT rely on maps,
In the example, a map doesn't seem the right structure anyway. Of course it's just an example, but if the data is sequential, an array will be more efficient. Inserting a new element in a map is efficient, but if it always ends up at the end, inserting into a pre-allocated array buffer will be more efficient (e.g. a circular buffer). Reading back the map will be slower too, as the tree needs to be traversed.
@Jonzarwal wrote:but i though it was nice to share this with you.
It is nice. Thanks for sharing!