Changeset 2355 in josm for trunk


Ignore:
Timestamp:
2009-10-30T23:03:15+01:00 (14 years ago)
Author:
Gubaer
Message:

applied #3819: patch by hansendc: QuadBuckets upate

File:
1 edited

Legend:

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

    r2353 r2355  
    213213        }
    214214    }
     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
    215238    class QBLevel
    216239    {
     
    370393            }
    371394        }
    372         /*
    373          * This is a quick hack.  The problem is that we need the
    374          * way's bounding box a *bunch* of times when it gets
    375          * inserted.  It gets expensive if we have to recreate
    376          * them each time.
    377          *
    378          * An alternative would be to calculate it at .add() time
    379          * 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         }
    394395
    395396        boolean matches(T o, BBox search_bbox)
     
    565566        QBLevel find_exact(T n)
    566567        {
    567             if (isLeaf())
    568                 return find_exact_leaf(n);
    569             return find_exact_branch(n);
    570         }
    571         QBLevel find_exact_leaf(T n)
    572         {
    573568            QBLevel ret = null;
    574569            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)) {
    581570                return this;
    582             }
    583            
     571            return find_exact_child(n);
     572        }
     573        private QBLevel find_exact_child(T n)
     574        {
    584575            QBLevel ret = null;
     576            if (children == null)
     577                return ret;
    585578            for (QBLevel l : children) {
    586579                if (l == null)
     
    893886        return this.remove(convert(o));
    894887    }
    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         */
    898917        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);
    901922        return ret;
    902923    }
     
    10881109            // search
    10891110            while (!search_cache.bbox().bounds(search_bbox)) {
    1090                 out("bbox: " + search_bbox);
     1111                if (debug)
     1112                    out("bbox: " + search_bbox);
    10911113                if (debug) {
    10921114                    out("search_cache: " + search_cache + " level: " + search_cache.level);
Note: See TracChangeset for help on using the changeset viewer.