Changeset 2355 in josm
- Timestamp:
- 2009-10-30T23:03:15+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r2353 r2355 213 213 } 214 214 } 215 /* 216 * This is a quick hack. The problem is that we need the 217 * way's bounding box a *bunch* of times when it gets 218 * inserted. It gets expensive if we have to recreate 219 * them each time. 220 * 221 * An alternative would be to calculate it at .add() time 222 * and passing it down the call chain. 223 */ 224 HashMap<Way,BBox> way_bbox_cache = new HashMap<Way, BBox>(); 225 BBox way_bbox(Way w) 226 { 227 if (way_bbox_cache.size() > 100) 228 way_bbox_cache.clear(); 229 BBox b = way_bbox_cache.get(w); 230 if (b == null) { 231 b = new BBox(w); 232 way_bbox_cache.put(w, b); 233 } 234 return b; 235 //return new BBox(w); 236 } 237 215 238 class QBLevel 216 239 { … … 370 393 } 371 394 } 372 /*373 * This is a quick hack. The problem is that we need the374 * way's bounding box a *bunch* of times when it gets375 * inserted. It gets expensive if we have to recreate376 * them each time.377 *378 * An alternative would be to calculate it at .add() time379 * and passing it down the call chain.380 */381 HashMap<Way,BBox> way_bbox_cache = new HashMap<Way, BBox>();382 BBox way_bbox(Way w)383 {384 if (way_bbox_cache.size() > 100)385 way_bbox_cache.clear();386 BBox b = way_bbox_cache.get(w);387 if (b == null) {388 b = new BBox(w);389 way_bbox_cache.put(w, b);390 }391 return b;392 //return new BBox(w);393 }394 395 395 396 boolean matches(T o, BBox search_bbox) … … 565 566 QBLevel find_exact(T n) 566 567 { 567 if (isLeaf())568 return find_exact_leaf(n);569 return find_exact_branch(n);570 }571 QBLevel find_exact_leaf(T n)572 {573 568 QBLevel ret = null; 574 569 if (content != null && content.contains(n)) 575 ret = this;576 return ret;577 }578 QBLevel find_exact_branch(T n)579 {580 if (content != null && content.contains(n)) {581 570 return this; 582 } 583 571 return find_exact_child(n); 572 } 573 private QBLevel find_exact_child(T n) 574 { 584 575 QBLevel ret = null; 576 if (children == null) 577 return ret; 585 578 for (QBLevel l : children) { 586 579 if (l == null) … … 893 886 return this.remove(convert(o)); 894 887 } 895 public boolean remove(T n) 896 { 897 QBLevel bucket = root.find_exact(n); 888 public boolean remove_slow(T removeme) 889 { 890 boolean ret = false; 891 Iterator<T> i = this.iterator(); 892 while (i.hasNext()) { 893 T o = i.next(); 894 if (o != removeme) 895 continue; 896 i.remove(); 897 ret = true; 898 break; 899 } 900 if (debug) 901 out("qb slow remove result: " + ret); 902 return ret; 903 } 904 public boolean remove(T o) 905 { 906 /* 907 * We first try a locational search 908 */ 909 QBLevel bucket = root.find_exact(o); 910 if (o instanceof Way) 911 way_bbox_cache.remove(o); 912 /* 913 * That may fail because the object was 914 * moved or changed in some way, so we 915 * resort to an iterative search: 916 */ 898 917 if (bucket == null) 899 return false; 900 boolean ret = bucket.remove_content(n); 918 return remove_slow(o); 919 boolean ret = bucket.remove_content(o); 920 if (debug) 921 out("qb remove result: " + ret); 901 922 return ret; 902 923 } … … 1088 1109 // search 1089 1110 while (!search_cache.bbox().bounds(search_bbox)) { 1090 out("bbox: " + search_bbox); 1111 if (debug) 1112 out("bbox: " + search_bbox); 1091 1113 if (debug) { 1092 1114 out("search_cache: " + search_cache + " level: " + search_cache.level);
Note:
See TracChangeset
for help on using the changeset viewer.