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

lastIsLabel removes labels from source array #3

Open
elgiano opened this issue Nov 29, 2019 · 0 comments
Open

lastIsLabel removes labels from source array #3

elgiano opened this issue Nov 29, 2019 · 0 comments

Comments

@elgiano
Copy link

elgiano commented Nov 29, 2019

a = 1!2!3;
a.collect(_.size); 
// -> [2,2,2]
KDTree(a,lastIsLabel:true);
a.collect(_.size); 
// -> [1,1,1]

In KDTree.sc:init() sorted = array.copy; is a shallow copy (the array is copied, but each point's coordinates, which are array themselves, gets referenced instead), so if(lastIsLabel, { label = location.pop }); pops from the original list.

I understand that we don't want to copy at every recursion of the init process, so a solution is to deep copy the original array when creating the tree. Maybe it should be said in the docs?

a = 1!2!3;
a.collect(_.size); 
// -> [2,2,2]
KDTree(a.collect(_.copy),lastIsLabel:true);
a.collect(_.size); 
// -> [2,2,2]
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