Changeset 5681 in josm for trunk/src/org/openstreetmap/josm/command
- Timestamp:
- 2013-01-27T20:07:53+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r5674 r5681 154 154 * Then add all ways, each preceded by its (remaining) nodes. 155 155 */ 156 top: 157 while (!in.isEmpty()) { 158 for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) { 159 OsmPrimitive u = it.next(); 160 if (u instanceof Way) { 161 Way w = (Way) u; 162 it.remove(); 163 for (Node n : w.getNodes()) { 164 if (in.contains(n)) { 165 in.remove(n); 166 out.add(n); 167 } 156 top: while (!in.isEmpty()) { 157 for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) { 158 OsmPrimitive u = it.next(); 159 if (u instanceof Way) { 160 Way w = (Way) u; 161 it.remove(); 162 for (Node n : w.getNodes()) { 163 if (in.contains(n)) { 164 in.remove(n); 165 out.add(n); 168 166 } 169 out.add(w); 170 continue top; 171 } 172 } 173 break; // no more ways left 174 } 175 176 /** 177 * Rest are relations. Do topological sorting on a DAG where each 178 * arrow points from child to parent. (Because it is faster to 179 * loop over getReferrers() than getMembers().) 180 */ 181 Set<Relation> inR = (Set) in; 182 Set<Relation> childlessR = new HashSet<Relation>(); 183 List<Relation> outR = new ArrayList<Relation>(inR.size()); 184 185 HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>(); 186 187 // calculate initial number of childs 188 for (Relation r : inR) { 189 numChilds.put(r, 0); 190 } 191 for (Relation r : inR) { 192 for (OsmPrimitive parent : r.getReferrers()) { 193 if (!(parent instanceof Relation)) 194 throw new AssertionError(); 195 Integer i = numChilds.get(parent); 196 if (i != null) { 197 numChilds.put((Relation)parent, i+1); 198 } 199 } 200 } 201 for (Relation r : inR) { 202 if (numChilds.get(r).equals(0)) { 203 childlessR.add(r); 204 } 205 } 206 207 while (!childlessR.isEmpty()) { 208 // Identify one childless Relation and 209 // let it virtually die. This makes other 210 // relations childless. 211 Iterator<Relation> it = childlessR.iterator(); 212 Relation next = it.next(); 213 it.remove(); 214 outR.add(next); 215 216 for (OsmPrimitive parentPrim : next.getReferrers()) { 217 Relation parent = (Relation) parentPrim; 218 Integer i = numChilds.get(parent); 219 if (i != null) { 220 numChilds.put(parent, i-1); 221 if (i-1 == 0) { 222 childlessR.add(parent); 223 } 224 } 225 } 226 } 227 228 if (outR.size() != inR.size()) 229 throw new AssertionError("topo sort algorithm failed"); 230 231 out.addAll(outR); 232 233 return out; 167 } 168 out.add(w); 169 continue top; 170 } 171 } 172 break; // no more ways left 173 } 174 175 /** 176 * Rest are relations. Do topological sorting on a DAG where each 177 * arrow points from child to parent. (Because it is faster to 178 * loop over getReferrers() than getMembers().) 179 */ 180 Set<Relation> inR = (Set) in; 181 Set<Relation> childlessR = new HashSet<Relation>(); 182 List<Relation> outR = new ArrayList<Relation>(inR.size()); 183 184 HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>(); 185 186 // calculate initial number of childs 187 for (Relation r : inR) { 188 numChilds.put(r, 0); 189 } 190 for (Relation r : inR) { 191 for (OsmPrimitive parent : r.getReferrers()) { 192 if (!(parent instanceof Relation)) 193 throw new AssertionError(); 194 Integer i = numChilds.get(parent); 195 if (i != null) { 196 numChilds.put((Relation)parent, i+1); 197 } 198 } 199 } 200 for (Relation r : inR) { 201 if (numChilds.get(r).equals(0)) { 202 childlessR.add(r); 203 } 204 } 205 206 while (!childlessR.isEmpty()) { 207 // Identify one childless Relation and 208 // let it virtually die. This makes other 209 // relations childless. 210 Iterator<Relation> it = childlessR.iterator(); 211 Relation next = it.next(); 212 it.remove(); 213 outR.add(next); 214 215 for (OsmPrimitive parentPrim : next.getReferrers()) { 216 Relation parent = (Relation) parentPrim; 217 Integer i = numChilds.get(parent); 218 if (i != null) { 219 numChilds.put(parent, i-1); 220 if (i-1 == 0) { 221 childlessR.add(parent); 222 } 223 } 224 } 225 } 226 227 if (outR.size() != inR.size()) 228 throw new AssertionError("topo sort algorithm failed"); 229 230 out.addAll(outR); 231 232 return out; 234 233 } 235 234
Note:
See TracChangeset
for help on using the changeset viewer.