0

I want to interleave/convert a jagged array of floats to one array. From:

[
    [0.32, 42.21, 13.37, 32.2],
    [0.34, 21.2, 4335343.2, 420.2],
    [0.1, 727.22, 12.4, 7.27]
]

to

[0.32, 0.34, 0.1, 42.21, 21.2, 727.22, 13.37, 4335343.2, 12.4, 32.2, 420.2, 7.27]

The amount of elements is not known at runtime, but there is always going to be at least two, and the amount of elements in each array in the jagged array is going to be equal. I also then need to de-interleave that array - basically a reversal of what I described above.

How can I do this in C# without a big performance impact?

boooba
  • 149
  • 2
  • 12
  • 1
    *How can I do this in C# without a big performance impact?* - define performance – Caius Jard May 05 '22 at 18:31
  • @KirkWoll That doesn't interleave the arrays, that flattens them - please look at the example I've provided – boooba May 05 '22 at 18:32
  • @boooba, I see, thanks for pointing that out. – Kirk Woll May 05 '22 at 18:34
  • You need an implementation of Zip that keeps going and works on N arrays. There is an SO question lying around somewhere with various approaches. I'll see if I can find it – Caius Jard May 05 '22 at 18:34
  • @CaiusJard Well, I don't really know how the "best" solution would perform for this scenario, but I would imagine, for something with good performance, you would do something along the lines of https://stackoverflow.com/questions/961707/de-interleave-array-fast-in-c-sharp. I tried implementing that to work for my use case, but I can't figure out how :/ – boooba May 05 '22 at 18:34
  • @boooba Then you should edit your question to include what you tried, what happened when you did, and how that differs from what you want. – Servy May 05 '22 at 19:16
  • We got a lot of "I need it performant" but often people asking for it don't show us what they have, or give an indication of the required performance and how it doesn't meet meet it – Caius Jard May 05 '22 at 19:18

0 Answers0