Quote:
I wasn't clear enough, transform is fine, the problem is it's use, if I haven't misread your code, if it's placing the queen on a given row, transform will be called on all the rows from that current row plus 1 up to N. This means that if you backtrack before the last row some calculation will have been made for nothing. Is it a huge impact? I honestly don't know.
That's a point I'll have to think about. Unfortunately, if we already knew we were going to backtrack before we transformed the array, we wouldn't need to transform the array. Furthermore, we don't save anything by not detecting that the very next row is completely threatened.
What we could do is insert code into the
transform functor to determine whether there are any dominated rows already, starting two rows down, and if so stop copying. I'm doubtful this will improve performance, for two reasons: the vast majority of the time, there won't be any dominated rows that far below us, and this would probably inhibit the compiler from generating SIMD instructions for the loop. As an alternative, we could finish the loop and then scan for dominated rows over the horizon, but that would make the rest of the program do more work.
Quote:
I would also like to point out the other brillant idea you had to eliminate the need to try the middle row on odd N
Thank you. That's actually the basis for my refactoring.