It using Array.prototype.slice under the hood, but the way Arrays in Elm is implemented is by using trees. I suggest you watch my talk from Elm Europe, where I explain how the different data structures work in detail =)
https://www.youtube.com/watch?v=mmiNobpx7eI fredag 17. november 2017 13.34.08 UTC+1 skrev Francisco Ramos følgende: > > That was a good observation, Rupert. Well, it doesn't return Nothing if > the indexes are out of the bounds, but if start < 0 then start = 0, and end > >= length then end = length -1... I could actually use Array.get and > implement my own map like you mention. > > Thanks Robin for that correction. I thought Array.slice is using under the > hood Array.prototype.slice, which as far as I know, the C++ implementation, > it's O(N). If there is a new implementation with such complexity, then > happy days. > > Was just curious to know what ideas there are out there about this > problem. I'm aware of the fact that 2 * O(N) is still O(N), but my arrays > might be dealing with millions of entries. Imagine a 5000px by 5000px by 3 > color channels. That's 75 millions. So performance is very important. > That's why I'm asking. > > Thanks guys > > On Fri, Nov 17, 2017 at 1:20 PM Robin Heggelund Hansen <[email protected] > <javascript:>> wrote: > >> Slicing isn't O(N). >> >> In the current implementation in core, slicing is O(log32n) i believe. In >> the next version of Elm, slicing is O(log32n) when start = 0; I'm uncertain >> what the big-o notation is once start > 0 though. >> >> >> fredag 17. november 2017 09.25.22 UTC+1 skrev Francisco Ramos følgende: >>> >>> Hi there, >>> >>> Was wondering how I can map over an array with a start and end indexes. >>> I know I could slice the array and then map, but performance is a concern >>> and slicing is O(N) where N = end - start, plus the actual mapping, another >>> O(N). >>> >>> Maybe there is another way where I just loop once over the array? >>> >>> Thanks a lot, >>> Fran >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Elm Discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
