Changeset 7501 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-09-05T14:45:30+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10483 - drastic improvement of data consistency test performance

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r7395 r7501  
    102102    private static final int MAX_EVENTS = 1000;
    103103
    104     private Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);
    105     private Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash());
    106     private CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>();
     104    private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);
     105    private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash());
     106    private final CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>();
    107107
    108108    // provide means to highlight map elements that are not osm primitives
     
    257257     * conversion of the whole DataSet by iterating over this data structure.
    258258     */
    259     private QuadBuckets<Node> nodes = new QuadBuckets<>();
     259    private final QuadBuckets<Node> nodes = new QuadBuckets<>();
    260260
    261261    private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<OsmPrimitive> predicate) {
     
    287287
    288288    /**
     289     * Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
     290     * For efficiency reasons this method does not lock the dataset, you have to lock it manually.
     291     *
     292     * @param n The node to search
     293     * @return {@code true} if {@code n} ban be retrieved in this data set, {@code false} otherwise
     294     * @since 7501
     295     */
     296    public boolean containsNode(Node n) {
     297        return nodes.contains(n);
     298    }
     299
     300    /**
    289301     * All ways (Streets etc.) in the DataSet.
    290302     *
    291303     * The way nodes are stored only in the way list.
    292304     */
    293     private QuadBuckets<Way> ways = new QuadBuckets<>();
     305    private final QuadBuckets<Way> ways = new QuadBuckets<>();
    294306
    295307    /**
     
    317329
    318330    /**
     331     * Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
     332     * For efficiency reasons this method does not lock the dataset, you have to lock it manually.
     333     *
     334     * @param w The way to search
     335     * @return {@code true} if {@code w} ban be retrieved in this data set, {@code false} otherwise
     336     * @since 7501
     337     */
     338    public boolean containsWay(Way w) {
     339        return ways.contains(w);
     340    }
     341
     342    /**
    319343     * All relations/relationships
    320344     */
    321     private Collection<Relation> relations = new ArrayList<>();
     345    private final Collection<Relation> relations = new ArrayList<>();
    322346
    323347    /**
     
    349373            lock.readLock().unlock();
    350374        }
     375    }
     376
     377    /**
     378     * Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
     379     * For efficiency reasons this method does not lock the dataset, you have to lock it manually.
     380     *
     381     * @param r The relation to search
     382     * @return {@code true} if {@code r} ban be retrieved in this data set, {@code false} otherwise
     383     * @since 7501
     384     */
     385    public boolean containsRelation(Relation r) {
     386        return relations.contains(r);
    351387    }
    352388
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r7500 r7501  
    99
    1010import org.openstreetmap.josm.Main;
    11 import org.openstreetmap.josm.data.coor.LatLon;
    1211import org.openstreetmap.josm.tools.Utils;
    1312
     
    105104    public void searchNodes() {
    106105        long startTime = System.currentTimeMillis();
    107         for (Node n : dataSet.getNodes()) {
    108             if (!n.isIncomplete() && !n.isDeleted()) {
    109                 LatLon c = n.getCoor();
    110                 if (c != null) {
    111                     BBox box = c.toBBox(0.0001);
    112                     if (!dataSet.searchNodes(box).contains(n)) {
    113                         printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n);
    114                     }
    115                 }
    116             }
     106        dataSet.getReadLock().lock();
     107        try {
     108            for (Node n : dataSet.getNodes()) {
     109                // Call isDrawable() as an efficient replacement to previous checks (!deleted, !incomplete, getCoor() != null)
     110                if (n.isDrawable() && !dataSet.containsNode(n)) {
     111                    printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n);
     112                }
     113            }
     114        } finally {
     115            dataSet.getReadLock().unlock();
    117116        }
    118117        printElapsedTime(startTime);
     
    124123    public void searchWays() {
    125124        long startTime = System.currentTimeMillis();
    126         for (Way w : dataSet.getWays()) {
    127             if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.searchWays(w.getBBox()).contains(w)) {
    128                 printError("SEARCH WAYS", "%s not found using Dataset.searchWays()", w);
    129             }
     125        dataSet.getReadLock().lock();
     126        try {
     127            for (Way w : dataSet.getWays()) {
     128                if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.containsWay(w)) {
     129                    printError("SEARCH WAYS", "%s not found using Dataset.searchWays()", w);
     130                }
     131            }
     132        } finally {
     133            dataSet.getReadLock().unlock();
    130134        }
    131135        printElapsedTime(startTime);
Note: See TracChangeset for help on using the changeset viewer.