コード例 #1
0
  private void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory) {
    boolean wasUnloaded = ts.isUnloaded();
    int ucount = ts.getUnloadCont();
    if (nativeLib == null) {
      long now = System.nanoTime();
      try {
        BinaryMapIndexReader reader = reverseMap.get(ts.subregion.routeReg);
        ts.setLoadedNonNative();
        List<RouteDataObject> res = reader.loadRouteIndexData(ts.subregion);
        //				System.out.println(ts.subregion.shiftToData + " " + res);
        for (RouteDataObject ro : res) {
          if (ro != null && config.router.acceptLine(ro)) {
            ts.add(ro);
          }
        }
      } catch (IOException e) {
        throw new RuntimeException("Loading data exception", e);
      }

      timeToLoad += (System.nanoTime() - now);
    } else {
      long now = System.nanoTime();
      NativeRouteSearchResult ns = nativeLib.loadRouteRegion(ts.subregion, loadObjectsInMemory);
      //			System.out.println(ts.subregion.shiftToData + " " + Arrays.toString(ns.objects));
      ts.setLoadedNative(ns, this);
      timeToLoad += (System.nanoTime() - now);
    }
    loadedTiles++;
    if (wasUnloaded) {
      if (ucount == 1) {
        loadedPrevUnloadedTiles++;
      }
    } else {
      if (global != null) {
        global.allRoutes += ts.tileStatistics.allRoutes;
        global.coordinates += ts.tileStatistics.coordinates;
      }
      distinctLoadedTiles++;
    }
    global.size += ts.tileStatistics.size;
  }
コード例 #2
0
 public void unloadAllData(RoutingContext except) {
   for (RoutingSubregionTile tl : subregionTiles) {
     if (tl.isLoaded()) {
       if (except == null || except.searchSubregionTile(tl.subregion) < 0) {
         tl.unload();
         unloadedTiles++;
         global.size -= tl.tileStatistics.size;
       }
     }
   }
   subregionTiles.clear();
   tileRoutes.clear();
   indexedSubregions.clear();
 }
コード例 #3
0
 public void setLoadedNative(NativeRouteSearchResult r, RoutingContext ctx) {
   isLoaded = Math.abs(isLoaded) + 1;
   tileStatistics = new TileStatistics();
   if (r.objects != null) {
     searchResult = null;
     routes = new TLongObjectHashMap<BinaryRoutePlanner.RouteSegment>();
     for (RouteDataObject ro : r.objects) {
       if (ro != null && ctx.config.router.acceptLine(ro)) {
         add(ro);
       }
     }
   } else {
     searchResult = r;
     tileStatistics.size += 100;
   }
 }
コード例 #4
0
  public void unloadUnusedTiles(int memoryLimit) {
    float desirableSize = memoryLimit * 0.7f;
    List<RoutingSubregionTile> list =
        new ArrayList<RoutingSubregionTile>(subregionTiles.size() / 2);
    int loaded = 0;
    for (RoutingSubregionTile t : subregionTiles) {
      if (t.isLoaded()) {
        list.add(t);
        loaded++;
      }
    }
    maxLoadedTiles = Math.max(maxLoadedTiles, getCurrentlyLoadedTiles());
    Collections.sort(
        list,
        new Comparator<RoutingSubregionTile>() {
          private int pow(int base, int pw) {
            int r = 1;
            for (int i = 0; i < pw; i++) {
              r *= base;
            }
            return r;
          }

          @Override
          public int compare(RoutingSubregionTile o1, RoutingSubregionTile o2) {
            int v1 = (o1.access + 1) * pow(10, o1.getUnloadCont() - 1);
            int v2 = (o2.access + 1) * pow(10, o2.getUnloadCont() - 1);
            return v1 < v2 ? -1 : (v1 == v2 ? 0 : 1);
          }
        });
    int i = 0;
    while (getCurrentEstimatedSize() >= desirableSize
        && (list.size() - i) > loaded / 5
        && i < list.size()) {
      RoutingSubregionTile unload = list.get(i);
      i++;
      //			System.out.println("Unload " + unload);
      unload.unload();
      unloadedTiles++;
      global.size -= unload.tileStatistics.size;
      // tile could be cleaned from routing tiles and deleted from whole list

    }
    for (RoutingSubregionTile t : subregionTiles) {
      t.access /= 3;
    }
  }
コード例 #5
0
 public void add(RouteDataObject ro) {
   tileStatistics.addObject(ro);
   for (int i = 0; i < ro.pointsX.length; i++) {
     int x31 = ro.getPoint31XTile(i);
     int y31 = ro.getPoint31YTile(i);
     long l = (((long) x31) << 31) + (long) y31;
     RouteSegment segment = new RouteSegment(ro, i);
     if (!routes.containsKey(l)) {
       routes.put(l, segment);
     } else {
       RouteSegment orig = routes.get(l);
       while (orig.next != null) {
         orig = orig.next;
       }
       orig.next = segment;
     }
   }
 }