public int[] intersection(SparseVector other) {
        List<Integer> diffIndicesList = new ArrayList<>();

        Iterator<VectorTuple> itr = iterator();
        Iterator<VectorTuple> otherItr = other.iterator();
        if (itr.hasNext() && otherItr.hasNext()) {
            VectorTuple tuple = itr.next();
            VectorTuple otherTuple = otherItr.next();
            while (itr.hasNext() && otherItr.hasNext()) {
                if (tuple.index == otherTuple.index) {
                    diffIndicesList.add(tuple.index);
                    tuple = itr.next();
                    otherTuple = otherItr.next();
                } else if (tuple.index < otherTuple.index) {
                    tuple = itr.next();
                } else {
                    otherTuple = otherItr.next();
                }
            }
            while (itr.hasNext()) {
                if (tuple.index == otherTuple.index) {
                    diffIndicesList.add(tuple.index);
                }
                tuple = itr.next();
            }
            while (otherItr.hasNext()) {
                if (tuple.index == otherTuple.index) {
                    diffIndicesList.add(tuple.index);
                }
                otherTuple = otherItr.next();
            }
            if (tuple.index == otherTuple.index) {
                diffIndicesList.add(tuple.index);
            }
        }

        return Util.toPrimitiveInt(diffIndicesList);
    }
@Test
    public void intersection() {
        SparseVector a = generateVectorA();
        SparseVector b = generateVectorB();
        SparseVector c = generateVectorC();
        SparseVector empty = generateEmptyVector();

        assertArrayEquals(a.intersection(b), new int[]{0,1,4,5,8});
        assertArrayEquals(a.intersection(c), new int[]{1,5});
        assertArrayEquals(a.intersection(empty), new int[0]);
    }