public int put( K key, int value ) { synchronized( mutex ) { return m.put( key, value ); } } public int remove( Object key ) {
public synchronized void updateTargetWorkerCounts (Multimap<String, String> activeJobsPerGraph) { final int activeWorkerCount = observationsByWorkerId.size(); // (plus outstanding instance requests) final int activeJobsCount = activeJobsPerGraph.size(); // For now just distribute among all jobs equally, without weighting by users. activeJobsPerGraph.asMap().forEach((g, js) -> { targetWorkerCountPerGraph.put(g, js.size() * activeWorkerCount / activeJobsCount); // FIXME this will round down and waste workers }); }
@Override public boolean put(TransitStop t, int time, boolean transfer) { // This does not store internal algorithm state as it used to, but rather only the output. // The reasoning is that, in dynamic programming/range RAPTOR mode, bestStops is carried over between runs of // the algorithm. But you still want to propagate a non-optimal time with fewer transfers, because the // optimal time at this stop might have already used up all of the transfers. if (!transfer && time < bestStops.get(t)) bestStops.put(t, time); if (time < matrix[current].get(t)) { matrix[current].put(t, time); return true; } return false; }
public static TimeSurface.RangeSet makeSurfaces (AnalystProfileRouterPrototype profileRouter) { TimeSurface minSurface = new TimeSurface(profileRouter); TimeSurface avgSurface = new TimeSurface(profileRouter); TimeSurface maxSurface = new TimeSurface(profileRouter); for (Map.Entry<Vertex, TimeRange> vtr : profileRouter.propagatedTimes.entrySet()) { Vertex v = vtr.getKey(); TimeRange tr = vtr.getValue(); minSurface.times.put(v, tr.min); avgSurface.times.put(v, tr.avg); maxSurface.times.put(v, tr.max); } RangeSet result = new RangeSet(); minSurface.description = "Travel times assuming best luck (never waiting for a transfer)."; avgSurface.description = "Expected travel times (average wait for every transfer)."; maxSurface.description = "Travel times assuming worst luck (maximum wait for every transfer)."; result.min = minSurface; result.avg = avgSurface; result.max = maxSurface; return result; }
@Override public boolean put(ProfileState ps) { if (ps.lowerBound < minUpperBounds.get(ps.stop)) { states.put(ps.stop, ps); if (ps.upperBound < minUpperBounds.get(ps.stop)) { minUpperBounds.put(ps.stop, ps.upperBound); // kick out old states for (Iterator<ProfileState> it = states.get(ps.stop).iterator(); it.hasNext();) { // need to use strictly-greater-than here, so states with no variation don't dominate themselves. if (it.next().lowerBound > ps.upperBound) { it.remove(); } } } return true; } else { return false; } }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Integer</code> value * @return the previous value associated with <tt>key</tt>, * or Integer(0) if none was found. */ public Integer put( K key, Integer value ) { if ( value == null ) return wrapValue( _map.put( key, _map.getNoEntryValue() ) ); return wrapValue( _map.put( key, unwrapValue( value ) ) ); }
@Override public boolean put(ProfileState ps) { if (ps.lowerBound >= minUpperBounds.get(ps.stop)) return false; ps.previous = null; if (ps.upperBound < minUpperBounds.get(ps.stop)) minUpperBounds.put(ps.stop, ps.upperBound); if (states.containsKey(ps.stop)) { // merge it in; it is not dominates ProfileState o = states.get(ps.stop); o.mergeIn(ps); } else { ps.patterns = null; states.put(ps.stop, ps); } return true; }
private int indexTile(ResourceUrn uri) { if (tiles.size() == MAX_TILES) { logger.error("Maximum tiles exceeded"); return 0; } Optional<BlockTile> tile = Assets.get(uri, BlockTile.class); if (tile.isPresent()) { if (checkTile(tile.get())) { int index = tiles.size(); tiles.add(tile.get()); addNormal(uri); addHeightMap(uri); addGlossMap(uri); tileIndexes.put(uri, index); tile.get().subscribe(tileReloadListener); return index; } else { logger.error("Invalid tile {}, must be a square with power-of-two sides.", uri); return 0; } } return 0; }
/** * Build the ID - Index map if needed. */ private synchronized void buildIdIndexMapIfNeeded () { // we check again if the map has been built. It's possible that it would have been built // by this method in another thread while this instantiation was blocked. if (idIndexMap == null) { // make a local object, don't expose to public view until it's built TObjectIntMap idIndexMap = new TObjectIntHashMap<String>(this.capacity, 1f, -1); for (int i = 0; i < this.capacity; i++) { if (ids[i] != null) { if (idIndexMap.containsKey(ids[i])) { LOG.error("Duplicate ID {} in pointset.", ids[i]); } else { idIndexMap.put(ids[i], i); } } } // now expose to public view; reference assignment is an atomic operation this.idIndexMap = idIndexMap; } }
public TimeSurface.RangeSet makeSurfaces(RepeatedRaptorProfileRouter repeatedRaptorProfileRouter) { TimeSurface.RangeSet rangeSet = new TimeSurface.RangeSet(); rangeSet.min = new TimeSurface(repeatedRaptorProfileRouter); rangeSet.avg = new TimeSurface(repeatedRaptorProfileRouter); rangeSet.max = new TimeSurface(repeatedRaptorProfileRouter); for (Vertex vertex : graph.index.vertexForId.values()) { int min = mins[vertex.getIndex()]; int max = maxs[vertex.getIndex()]; int avg = avgs[vertex.getIndex()]; if (avg == Integer.MAX_VALUE) continue; // Count is positive, extrema and sum must also be present rangeSet.min.times.put(vertex, min); rangeSet.max.times.put(vertex, max); rangeSet.avg.times.put(vertex, avg); } return rangeSet; }
private int getUniformLocation(int activeShaderProgramId, String desc) { UniformId id = new UniformId(activeShaderProgramId, desc); if (uniformLocationMap.containsKey(id)) { return uniformLocationMap.get(id); } int loc = GL20.glGetUniformLocation(activeShaderProgramId, desc); uniformLocationMap.put(id, loc); return loc; }
@Override public void visitVertex(State state) { Vertex vertex = state.getVertex(); if (vertex instanceof TransitStop) { Stop stop = ((TransitStop)vertex).getStop(); if (stopsFound.containsKey(stop)) return; // record only the closest stop in each cluster stopsFound.put(stop, (int) state.getElapsedTimeSeconds()); } } }
if (ps.lowerBound < minBoardTime.get(pattern)) { optimalBoardingLocation.put(pattern, ps); minBoardTime.put(pattern, ps.lowerBound);
int t = (int) state.getActiveTime(); if (existing == UNREACHABLE || existing > t) { times.put(vertex, t);
@Override public void proceed() { for (TObjectIntIterator<TransitStop> it = matrix[current].iterator(); it.hasNext();) { it.advance(); if (it.value() < matrix[current + 1].get(it.key())) matrix[current + 1].put(it.key(), it.value()); } current++; }
@Override public void setTexture(String desc, Texture texture) { if (isDisposed()) { return; } int texId; if (bindMap.containsKey(desc)) { texId = bindMap.get(desc); } else { // TODO: do this initially, and try and have similar textures in similar slots for all materials. ShaderParameterMetadata metadata = shader.getParameter(desc); if (metadata == null || !metadata.getType().isTexture()) { return; } texId = textureIndex++; // Make sure to bind the texture for all permutations setInt(desc, texId); bindMap.put(desc, texId); } textureMap.put(texId, texture); }
data.packetMap.put( packetClass, mapping.packetID ); data.packetConstructors[mapping.packetID] = constructor;
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Integer</code> value * @return the previous value associated with <tt>key</tt>, * or Integer(0) if none was found. */ public Integer put( K key, Integer value ) { if ( value == null ) return wrapValue( _map.put( key, _map.getNoEntryValue() ) ); return wrapValue( _map.put( key, unwrapValue( value ) ) ); }