Пример #1
0
  private void process(OsmRelation relation) {
    boolean hasChildRelations = false;
    TLongList childRelationMembers = new TLongArrayList();
    for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
      if (member.getType() == EntityType.Relation) {
        hasChildRelations = true;
        idsIsChildRelation.add(member.getId());
        childRelationMembers.add(member.getId());
        if (storeSimpleRelations) {
          idsSimpleRelations.remove(member.getId());
        }
      }
    }
    long id = relation.getId();
    if (hasChildRelations) {
      idsHasChildRelations.add(id);
      if (!graph.getNodes().contains(id)) {
        graph.addNode(id);
      }

      TLongIterator iterator = childRelationMembers.iterator();
      while (iterator.hasNext()) {
        long member = iterator.next();
        if (!graph.getNodes().contains(member)) {
          graph.addNode(member);
        }
        graph.addEdge(id, member);
      }
    } else {
      if (storeSimpleRelations && !idsIsChildRelation.contains(id)) {
        idsSimpleRelations.add(id);
      }
      numNoChildren++;
    }
  }
Пример #2
0
 @Override
 public void run() {
   long time = System.currentTimeMillis();
   timings.add(time - lastTime);
   lastTime = time;
   if (timings.size() > MAX_MEASUREMENTS) {
     timings.removeAt(0);
   }
   final int size = timings.size();
   if (size > 20) {
     TLongIterator i = timings.iterator();
     int count = 0;
     long last20 = 0;
     long total = 0;
     while (i.hasNext()) {
       long next = i.next();
       if (count > size - 20) {
         last20 += next;
       }
       total += next;
       count++;
     }
     ticksPerSecond.set(1000F / (last20 / 20F));
     avgTicksPerSecond.set(1000F / (total / ((float) size)));
   }
 }
Пример #3
0
  public void loadTileData(int x31, int y31, int zoomAround, final List<RouteDataObject> toFillIn) {
    int t = config.ZOOM_TO_LOAD_TILES - zoomAround;
    int coordinatesShift = (1 << (31 - config.ZOOM_TO_LOAD_TILES));
    if (t <= 0) {
      t = 1;
      coordinatesShift = (1 << (31 - zoomAround));
    } else {
      t = 1 << t;
    }

    TLongHashSet ts = new TLongHashSet();
    long now = System.nanoTime();
    for (int i = -t; i <= t; i++) {
      for (int j = -t; j <= t; j++) {
        ts.add(
            getRoutingTile(
                x31 + i * coordinatesShift, y31 + j * coordinatesShift, 0, OPTION_IN_MEMORY_LOAD));
      }
    }
    TLongIterator it = ts.iterator();
    while (it.hasNext()) {
      getAllObjects(it.next(), toFillIn);
    }
    timeToFindInitialSegments += (System.nanoTime() - now);
  }
Пример #4
0
 public double getValue(CostFunction f) {
   double s = 0;
   for (TLongIterator i = f.iterator(); i.hasNext(); ) {
     s += Math.abs(f.getValue(i.next()));
   }
   return s;
 }
Пример #5
0
 /** {@inheritDoc} */
 public boolean containsAll(TLongCollection collection) {
   TLongIterator iter = collection.iterator();
   while (iter.hasNext()) {
     if (!TLongLongHashMap.this.containsValue(iter.next())) {
       return false;
     }
   }
   return true;
 }
Пример #6
0
 public double getValue(CostFunction f, double boundValue) {
   double s = 0;
   for (TLongIterator i = f.iterator(); i.hasNext(); ) {
     double v = f.getValue(i.next());
     s += Math.abs(v);
   }
   s += f.getNumberOfNoGoods() * boundValue;
   return s;
 }
Пример #7
0
 /** {@inheritDoc} */
 @SuppressWarnings({"SuspiciousMethodCalls"})
 public boolean retainAll(Collection<?> collection) {
   boolean modified = false;
   TLongIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(Long.valueOf(iter.next()))) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
Пример #8
0
 /** {@inheritDoc} */
 public boolean retainAll(TLongCollection collection) {
   if (this == collection) {
     return false;
   }
   boolean modified = false;
   TLongIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(iter.next())) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
Пример #9
0
 /** {@inheritDoc} */
 public boolean removeAll(TLongCollection collection) {
   if (this == collection) {
     clear();
     return true;
   }
   boolean changed = false;
   TLongIterator iter = collection.iterator();
   while (iter.hasNext()) {
     long element = iter.next();
     if (remove(element)) {
       changed = true;
     }
   }
   return changed;
 }
  private void test(List<TLongSet> values) throws Exception {
    StringField id = new StringField("_id", "", Field.Store.NO);

    for (int i = 0; i < values.size(); ++i) {
      Document doc = new Document();
      id.setStringValue("" + i);
      doc.add(id);
      final TLongSet v = values.get(i);
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        LongField value = new LongField("value", it.next(), Field.Store.NO);
        doc.add(value);
      }
      writer.addDocument(doc);
    }
    writer.forceMerge(1);

    final IndexNumericFieldData indexFieldData = getForField("value");
    final AtomicNumericFieldData atomicFieldData = indexFieldData.load(refreshReader());
    final LongValues data = atomicFieldData.getLongValues();
    final DoubleValues doubleData = atomicFieldData.getDoubleValues();
    final TLongSet set = new TLongHashSet();
    final TDoubleSet doubleSet = new TDoubleHashSet();
    for (int i = 0; i < values.size(); ++i) {
      final TLongSet v = values.get(i);

      assertThat(data.hasValue(i), equalTo(!v.isEmpty()));
      assertThat(doubleData.hasValue(i), equalTo(!v.isEmpty()));

      if (v.isEmpty()) {
        assertThat(data.getValue(i), equalTo(0L));
        assertThat(doubleData.getValue(i), equalTo(0d));
      }

      set.clear();
      for (LongValues.Iter iter = data.getIter(i); iter.hasNext(); ) {
        set.add(iter.next());
      }
      assertThat(set, equalTo(v));

      final TDoubleSet doubleV = new TDoubleHashSet();
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        doubleV.add((double) it.next());
      }
      doubleSet.clear();
      for (DoubleValues.Iter iter = doubleData.getIter(i); iter.hasNext(); ) {
        doubleSet.add(iter.next());
      }
      assertThat(doubleSet, equalTo(doubleV));
    }
  }
Пример #11
0
  @Override
  public void run() {
    long[] chunkBuffer = new long[10];
    int chunkBufferSize = 0;
    TLongIterator iter;
    int i, cx, cy, cz;
    int idleCounter = 0;
    this.running = SpoutConfiguration.LIGHTING_ENABLED.getBoolean();
    long startTime = System.currentTimeMillis();
    boolean stop = false;
    SpoutSnapshotLock lock = (SpoutSnapshotLock) Spout.getEngine().getScheduler().getSnapshotLock();
    while (this.running) {
      boolean updated = false;
      // Obtain the chunks to work with
      synchronized (this.dirtyChunks) {
        if ((chunkBufferSize = this.dirtyChunks.size()) > 0) {
          if (chunkBufferSize > chunkBuffer.length) {
            chunkBuffer = new long[chunkBufferSize + 100];
          }
          iter = this.dirtyChunks.iterator();
          for (i = 0; i < chunkBufferSize && iter.hasNext(); i++) {
            chunkBuffer[i] = iter.next();
          }
          this.dirtyChunks.clear();
        }
      }
      if (updated = chunkBufferSize > 0) {
        lock.coreReadLock(taskName);
        try {
          // Resolve all chunks
          startTime = System.currentTimeMillis();
          stop = false;

          for (i = 0; i < chunkBufferSize; i++) {
            cx = Int21TripleHashed.key1(chunkBuffer[i]);
            cy = Int21TripleHashed.key2(chunkBuffer[i]);
            cz = Int21TripleHashed.key3(chunkBuffer[i]);
            if (stop) {
              // Add chunk back for next cycle
              this.addChunk(cx, cy, cz);
            } else {
              if (this.tmpChunks.load(cx, cy, cz, LoadOption.LOAD_ONLY).isLoadedAndPopulated()) {
                SpoutChunk center = this.tmpChunks.getCenter();
                if (center.isInitializingLighting.get()) {
                  // Schedule the chunk for a later check-up
                  this.addChunk(cx, cy, cz);
                } else {
                  while (this.skyLight.resolve(center)) ;
                  while (this.blockLight.resolve(center)) ;
                }
              }
              // Stop?
              stop = (System.currentTimeMillis() - startTime) >= MAX_CYCLE_TIME;
            }
          }
          idleCounter = 0;
        } finally {
          lock.coreReadUnlock(taskName);
        }
      }
      if (!updated) {
        if (idleCounter++ == 20) {
          this.skyLight.cleanUp();
          this.skyLight.reportChanges();
          this.blockLight.cleanUp();
          this.blockLight.reportChanges();
          this.tmpChunks.cleanUp();
        }
        try {
          Thread.sleep(50);
        } catch (InterruptedException ex) {
        }
      }
    }
  }
Пример #12
0
 private long any(TLongSet nodes) {
   TLongIterator iterator = nodes.iterator();
   long id = iterator.next();
   iterator.remove();
   return id;
 }