Skip to content

Issue with "remove" method #13

Description

@mgrutten

Some contents of the tree are unexpectedly disappearing during repeated calls to "remove". I have a simple example:

    private static class SimpleXY {
        private final double x;
        private final double y;

        public SimpleXY(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public double getX() {
            return x;
        }

        public double getY() {
            return y;
        }
    }

    private static class SimpleDistance implements DistanceFunction<SimpleXY> {

        @Override
        public double getDistance(SimpleXY pos1, SimpleXY pos2) {
            double xDiff = pos1.getX() - pos2.getX();
            double yDiff = pos1.getY() - pos2.getY();
            return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
        }
    }


    @Test
    void testRemove() {

        int nodeSize = 2;
        int numEntries = 4;
        List<SimpleXY> simpleXYList = new ArrayList<>(numEntries);
        Random random = new Random(0);

        for (int i = 0; i < numEntries; ++i) {
            simpleXYList.add(new SimpleXY(random.nextDouble(), random.nextDouble()));
        }

        final VPTree<SimpleXY, SimpleXY> vpTree = new VPTree<>(new SimpleDistance(),
                new SamplingMedianDistanceThresholdSelectionStrategy<>(
                        SamplingMedianDistanceThresholdSelectionStrategy.DEFAULT_NUMBER_OF_SAMPLES),
                nodeSize, simpleXYList);

        for (final SimpleXY s : simpleXYList) {
            System.out.println(vpTree.size());

            if (!vpTree.remove(s)) {
                throw new RuntimeException("Entry not removed");
            }
        }

    }

which has the following output:

4
0

java.lang.RuntimeException: Entry not removed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions