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

Possible accidental mutation #36

Open
GTRI-nathan opened this issue Jul 12, 2021 · 1 comment
Open

Possible accidental mutation #36

GTRI-nathan opened this issue Jul 12, 2021 · 1 comment

Comments

@GTRI-nathan
Copy link

Hi, first off, very cool library & benchmarks!

I'm not sure if I'm doing something wrong or making an incorrect assumption, but I think I've found a bug causing accidental mutation in List in 0.2.0-alpha6, see my minifed reproducer:

import io.lacuna.bifurcan.List;

public class Test {
        public static void main(String args[]) {
                int size = 32;
                List<Integer> a = new List<Integer>();
                List<Integer> b = new List<Integer>();
                for (int i = 0; i < size; i++) {
                        a = a.addLast(1);
                        b = b.addLast(1);
                }
                List<Integer> ap = a.set(15, 2);
                List<Integer> bp = b.set(15, 2);
                List<Integer> z = null;
                // Comment out, and the equals is true
                z = ap.set(15, 3);
                System.out.println("a: " + a);
                System.out.println("b: " + b);
                System.out.println("ap:" + ap);
                System.out.println("bp:" + bp);
                System.out.println("z: " + z);
                System.out.println("Should be true: " + ap.equals(bp));
        }
}

Will print:

~/test ➜ javac -cp "./bifurcan-0.2.0-alpha6.jar" Test.java && java -cp ".:./bifurcan-0.2.0-alpha6.jar" Test
a: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
b: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
ap:[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
bp:[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
z: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Should be true: false

Commenting out the z = ap.set(15,3); line, or changing the size to anything less than 32 will make the result true.

@ztellman
Copy link
Member

ztellman commented Jul 12, 2021 via email

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

2 participants