Ignore:
Timestamp:
2007-12-01T13:58:58+01:00 (18 years ago)
Author:
gebner
Message:

Speed up merging.

  • Don't scan our dataset for every primitive we merge. Use hashtables for that (at least for identical primitives for now).
  • Reverse the order we merge the layers when pressing the merge button in the layers list, so that when you merge 25 layers by pressing the merge button 25 times, you merge a small layer into a bigger one, and not the other way round.
File:
1 edited

Legend:

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

    r371 r478  
    3333        private final DataSet mergeds;
    3434
     35        private final HashMap<Long, Node> nodeshash = new HashMap<Long, Node>();
     36        private final HashMap<Long, Way> wayshash = new HashMap<Long, Way>();
     37        private final HashMap<Long, Relation> relshash = new HashMap<Long, Relation>();
     38
    3539        /**
    3640         * A list of all primitives that got replaced with other primitives.
     
    4448                this.ds = ds;
    4549                this.mergeds = mergeds;
     50
     51                for (Node n : ds.nodes) if (n.id != 0) nodeshash.put(n.id, n);
     52                for (Way w : ds.ways) if (w.id != 0) wayshash.put(w.id, w);
     53                for (Relation r : ds.relations) if (r.id != 0) relshash.put(r.id, r);
    4654        }
    4755
     
    5159         */
    5260        public void visit(Node other) {
    53                 if (mergeAfterId(ds.nodes, other))
     61                if (mergeAfterId(ds.nodes, nodeshash, other))
    5462                        return;
    5563
     
    8290        public void visit(Way other) {
    8391                fixWay(other);
    84                 if (mergeAfterId(ds.ways, other))
     92                if (mergeAfterId(ds.ways, wayshash, other))
    8593                        return;
    8694
     
    117125        public void visit(Relation other) {
    118126                fixRelation(other);
    119                 if (mergeAfterId(ds.relations, other))
     127                if (mergeAfterId(ds.relations, relshash, other))
    120128                        return;
    121129
     
    275283         * @return <code>true</code>, if no merge is needed or merge is performed already.
    276284         */
    277         private <P extends OsmPrimitive> boolean mergeAfterId(Collection<P> primitives, P other) {
     285        private <P extends OsmPrimitive> boolean mergeAfterId(
     286                        Collection<P> primitives, HashMap<Long, P> hash, P other) {
     287                // Fast-path merging of identical objects
     288                if (hash.containsKey(other.id)) {
     289                        P my = hash.get(other.id);
     290                        if (my.realEqual(other, true)) {
     291                                merged.put(other, my);
     292                                return true;
     293                        }
     294                }
     295
    278296                for (P my : primitives) {
    279297                        Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
Note: See TracChangeset for help on using the changeset viewer.