title: Cache-friendly copying of an array with readjustment by known index, gather, scatter
body: <p>Suppose we have an array of data and another array with indexes.</p>
  
  <pre><code>data = [1, 2, 3, 4, 5, 7]
  index = [5, 1, 4, 0, 2, 3]
  </code></pre>
  
  <p>We want to create a new array from elements of <code>data</code> at position from <code>index</code>. Result should be</p>
  
  <pre><code>[4, 2, 5, 7, 3, 1]
  </code></pre>
  
  <p>Naive algorithm works for O(N) but it performs random memory access.</p>
  
  <p>Can you suggest CPU cache friendly algorithm with the same complexity.</p>
  
  <p>PS
  In my certain case all elements in data array are integers. </p>
  
  <p>PPS
  Arrays might contain millions of elements. </p>
  
  <p>PPPS I'm ok with SSE/AVX or any other x64 specific optimizations</p>