Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep copy #3

Open
kasimi opened this issue Aug 4, 2016 · 1 comment
Open

Deep copy #3

kasimi opened this issue Aug 4, 2016 · 1 comment

Comments

@kasimi
Copy link
Contributor

kasimi commented Aug 4, 2016

Thanks for your work, I'm following this project with great interest.

I'm completely new to Go so I could be wrong about this. In these two lines

the intention of the loop is to copy the array values from row 0 to rows 1..n, however, what happens is that merely the references from row 0 are copied,

If I do colorError[0][0][0] = 999 after the loop, colorError[1][0][0] equals 999 too.

Also, you can simplify the code a tad by looping until i < errorRowCount - 1 and removing the % errorRowCount.

@kasimi
Copy link
Contributor Author

kasimi commented Aug 8, 2016

Please disregard my comment about the deep copy, I was mistaken. I now understand that the loops I linked to are supposed to shift the rows, not copy their values. However, I do think there's a bug because the loops effectively assign colorError[0] to colorError[1] and colorError[2] resulting in the issue with the 999.

Moreover, I think the last row needs to be zero'd before continuing with the calculations as it hasn't been visited by the algorithm yet.

Here is what I think should happen (Java):

// Remember first row
int[][] firstRow = colorError[0];

// Move rows one level up
for (int y = 1; y < colorError.length; y++) {
    colorError[y - 1] = colorError[y];
}

// Set new last row
colorError[colorError.length - 1] = firstRow;

// Zero last row
for (int x = 0; x < firstRow.length; x++) {
    Arrays.fill(firstRow[x], 0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant