Ticket #6241: unconnectedNodes.patch

File unconnectedNodes.patch, 3.7 KB (added by akks, 15 years ago)

patch for speed-up

  • org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

     
    4242    protected static final String PREFIX = ValidatorPreference.PREFIX + "." + UnconnectedWays.class.getSimpleName();
    4343
    4444    Set<MyWaySegment> ways;
    45     Set<Node> endnodes; // nodes at end of way
    46     Set<Node> endnodes_highway; // nodes at end of way
    47     Set<Node> middlenodes; // nodes in middle of way
     45    QuadBuckets<Node> endnodes; // nodes at end of way
     46    QuadBuckets<Node> endnodes_highway; // nodes at end of way
     47    QuadBuckets<Node> middlenodes; // nodes in middle of way
    4848    Set<Node> othernodes; // nodes appearing at least twice
    4949    //NodeSearchCache nodecache;
    5050    QuadBuckets<Node> nodecache;
     
    6666    public void startTest(ProgressMonitor monitor) {
    6767        super.startTest(monitor);
    6868        ways = new HashSet<MyWaySegment>();
    69         endnodes = new HashSet<Node>();
    70         endnodes_highway = new HashSet<Node>();
    71         middlenodes = new HashSet<Node>();
     69        endnodes = new QuadBuckets<Node>();
     70        endnodes_highway = new QuadBuckets<Node>();
     71        middlenodes = new QuadBuckets<Node>();
    7272        othernodes = new HashSet<Node>();
    7373        mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
    7474        minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
     
    9393                    //System.err.println("processing segment nr: " + nr + " of " + ways.size());
    9494                    last_print = now;
    9595                }
    96                 for (Node en : s.nearbyNodes(mindist)) {
     96                Collection<Node> nearbyNodes = s.nearbyNodes(mindist);
     97                for (Node en : nearbyNodes) {
    9798                    if (en == null || !s.highway || !endnodes_highway.contains(en)) {
    9899                        continue;
    99100                    }
     
    270271                    // the nodes that are not in the smaller
    271272                    // area, but keep the old larger cache.
    272273                    Set<Node> trimmed = new HashSet<Node>(nearbyNodeCache);
    273                     for (Node n : new HashSet<Node>(nearbyNodeCache)) {
     274                    Set<Node> initial = new HashSet<Node>(nearbyNodeCache);
     275                    for (Node n : initial) {
    274276                        if (!nearby(n, dist)) {
    275277                            trimmed.remove(n);
    276278                        }
     
    289291            // overlap a bit and can return duplicate nodes.
    290292            nearbyNodeCache = null;
    291293            List<LatLon> bounds = this.getBounds(dist);
    292             List<Node> found_nodes = ds.searchNodes(new BBox(bounds.get(0), bounds.get(1)));
     294            List<Node> found_nodes = endnodes_highway.search(new BBox(bounds.get(0), bounds.get(1)));
     295            found_nodes.addAll(endnodes.search(new BBox(bounds.get(0), bounds.get(1))));
     296
    293297            if (found_nodes == null)
    294298                return Collections.emptySet();
    295299
     
    347351    @Override
    348352    public void visit(Way w) {
    349353        ways.addAll(getWaySegments(w));
    350         Set<Node> set = endnodes;
     354        QuadBuckets<Node> set = endnodes;
    351355        if (w.hasKey("highway") || w.hasKey("railway")) {
    352356            set = endnodes_highway;
    353357        }
     
    359363    public void visit(Node n) {
    360364    }
    361365
    362     private void addNode(Node n, Set<Node> s) {
     366    private void addNode(Node n, QuadBuckets<Node> s) {
    363367        boolean m = middlenodes.contains(n);
    364368        boolean e = endnodes.contains(n);
    365369        boolean eh = endnodes_highway.contains(n);