Changeset 478 in josm for trunk/src/org


Ignore:
Timestamp:
2007-12-01T13:58:58+01:00 (16 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.
Location:
trunk/src/org/openstreetmap/josm
Files:
2 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();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r464 r478  
    251251                buttonPanel.add(deleteButton);
    252252
    253                 mergeButton.setToolTipText(tr("Merge the selected layer into the layer directly below."));
     253                mergeButton.setToolTipText(tr("Merge the layer directly below into the selected layer."));
    254254                mergeButton.addActionListener(new ActionListener(){
    255255                        public void actionPerformed(ActionEvent e) {
    256                                 Layer lFrom = (Layer)instance.getSelectedValue();
    257                                 Layer lTo = (Layer)model.get(instance.getSelectedIndex()+1);
     256                                Layer lTo = (Layer)instance.getSelectedValue();
     257                                Layer lFrom = (Layer)model.get(instance.getSelectedIndex()+1);
    258258                                lTo.mergeFrom(lFrom);
    259                                 instance.setSelectedValue(lTo, true);
    260259                                mapView.removeLayer(lFrom);
     260                                updateButtonEnabled();
     261                                mapView.repaint();
    261262                        }
    262263                });
     
    277278                boolean enable = model.getSize() > 1;
    278279                enable = enable && sel < model.getSize()-1;
    279                 enable = enable && l.isMergable((Layer)model.get(sel+1));
     280                enable = enable && ((Layer)model.get(sel+1)).isMergable(l);
    280281                mergeButton.setEnabled(enable);
    281282                upButton.setEnabled(sel > 0);
Note: See TracChangeset for help on using the changeset viewer.