Evil Algorithm, applying transformation vector in-place?
Posted: Fri 02 Jan, 2009 11:54 pm
This is quite annoying, and google isn't cooperating.
Suppose we have an array of data, called "data", and an array of incides called "indices" (very original..)
All indices [0 .. n-1] are present, and only once.
The array "result" is such that for every n, result[n] equals data[indices[n]].
Can the result be generated without copying the items of "data" into a new array? If so, how?
In other words, can "data" be modified in-place to have the property of "result"? (of course in that case the "data" used at the right hand side is taken from the old array, but that's just a technicality)
I really feel like it ought to be possible..
Suppose we have an array of data, called "data", and an array of incides called "indices" (very original..)
All indices [0 .. n-1] are present, and only once.
The array "result" is such that for every n, result[n] equals data[indices[n]].
Can the result be generated without copying the items of "data" into a new array? If so, how?
In other words, can "data" be modified in-place to have the property of "result"? (of course in that case the "data" used at the right hand side is taken from the old array, but that's just a technicality)
I really feel like it ought to be possible..