Changeset 5674 in josm for trunk/src/org/openstreetmap/josm/command
 Timestamp:
 20130126T21:50:46+01:00 (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r4918 r5674 16 16 17 17 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.Hash;19 18 import org.openstreetmap.josm.data.osm.Node; 20 19 import org.openstreetmap.josm.data.osm.NodeData; … … 65 64 66 65 protected void saveIncomplete(Collection<OsmPrimitive> makeIncomplete) { 67 makeIncompleteData = new Storage<PrimitiveData>(new Hash<PrimitiveData,PrimitiveData>() { 68 public int getHashCode(PrimitiveData k) { 69 return (int) k.getUniqueId(); 70 } 71 72 public boolean equals(PrimitiveData k, PrimitiveData t) { 73 return k.getUniqueId() == t.getUniqueId() && k.getType() == t.getType(); 74 } 75 }); 76 makeIncompleteData_byPrimId = makeIncompleteData.foreignKey(new Hash<PrimitiveId, PrimitiveData>() { 77 public int getHashCode(PrimitiveId k) { 78 return (int) k.getUniqueId(); 79 } 80 81 public boolean equals(PrimitiveId k, PrimitiveData t) { 82 return k.getUniqueId() == t.getUniqueId() && k.getType() == t.getType(); 83 } 84 }); 66 makeIncompleteData = new Storage<PrimitiveData>(new Storage.PrimitiveIdHash()); 67 makeIncompleteData_byPrimId = makeIncompleteData.foreignKey(new Storage.PrimitiveIdHash()); 85 68 86 69 for (OsmPrimitive osm : makeIncomplete) { … … 191 174 } 192 175 193 /**194 * Rest are relations. Do topological sorting on a DAG where each195 * arrow points from child to parent. (Because it is faster to196 * loop over getReferrers() than getMembers().)197 */198 Set<Relation> inR = (Set) in;199 Set<Relation> childlessR = new HashSet<Relation>();200 List<Relation> outR = new ArrayList<Relation>(inR.size());201 202 HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>();203 204 // calculate initial number of childs205 for (Relation r : inR) {206 numChilds.put(r, 0);207 }208 for (Relation r : inR) {209 for (OsmPrimitive parent : r.getReferrers()) {210 if (!(parent instanceof Relation))211 throw new AssertionError();212 Integer i = numChilds.get(parent);213 if (i != null) {214 numChilds.put((Relation)parent, i+1);215 }216 }217 }218 for (Relation r : inR) {219 if (numChilds.get(r).equals(0)) {220 childlessR.add(r);221 }222 }223 224 while (!childlessR.isEmpty()) {225 // Identify one childless Relation and226 // let it virtually die. This makes other227 // relations childless.228 Iterator<Relation> it = childlessR.iterator();229 Relation next = it.next();230 it.remove();231 outR.add(next);232 233 for (OsmPrimitive parentPrim : next.getReferrers()) {234 Relation parent = (Relation) parentPrim;235 Integer i = numChilds.get(parent);236 if (i != null) {237 numChilds.put(parent, i1);238 if (i1 == 0) {239 childlessR.add(parent);240 }241 }242 }243 }244 245 if (outR.size() != inR.size())246 throw new AssertionError("topo sort algorithm failed");247 248 out.addAll(outR);249 250 return out;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, i1); 221 if (i1 == 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; 251 234 } 252 235
Note: See TracChangeset
for help on using the changeset viewer.