예제 #1
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();
 }
예제 #2
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;
    }
  }