use of gnu.trove.map.hash.TIntObjectHashMap in project Osmand by osmandapp.
the class BinaryMapIndexReader method getTransportRoutes.
/**
* Transport public methods
*/
public TIntObjectHashMap<TransportRoute> getTransportRoutes(int[] filePointers) throws IOException {
TIntObjectHashMap<TransportRoute> result = new TIntObjectHashMap<TransportRoute>();
Map<TransportIndex, TIntArrayList> groupPoints = new HashMap<TransportIndex, TIntArrayList>();
for (int filePointer : filePointers) {
TransportIndex ind = getTransportIndex(filePointer);
if (ind != null) {
if (!groupPoints.containsKey(ind)) {
groupPoints.put(ind, new TIntArrayList());
}
groupPoints.get(ind).add(filePointer);
}
}
Iterator<Entry<TransportIndex, TIntArrayList>> it = groupPoints.entrySet().iterator();
if (it.hasNext()) {
Entry<TransportIndex, TIntArrayList> e = it.next();
TransportIndex ind = e.getKey();
TIntArrayList pointers = e.getValue();
pointers.sort();
TIntObjectHashMap<String> stringTable = new TIntObjectHashMap<String>();
for (int i = 0; i < pointers.size(); i++) {
int filePointer = pointers.get(i);
TransportRoute transportRoute = transportAdapter.getTransportRoute(filePointer, stringTable, false);
result.put(filePointer, transportRoute);
}
transportAdapter.initializeStringTable(ind, stringTable);
for (TransportRoute r : result.values(new TransportRoute[result.size()])) {
transportAdapter.initializeNames(false, r, stringTable);
}
}
return result;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project BuildCraft by BuildCraft.
the class IItemBuildCraft method registerVariants.
@SideOnly(Side.CLIENT)
default void registerVariants() {
Item thisItem = (Item) this;
TIntObjectHashMap<ModelResourceLocation> variants = new TIntObjectHashMap<>();
addModelVariants(variants);
for (int key : variants.keys()) {
ModelResourceLocation variant = variants.get(key);
if (RegistryConfig.DEBUG) {
BCLog.logger.info("[lib.registry][" + thisItem.getRegistryName() + "] Registering a variant " + variant + " for damage " + key);
}
ModelLoader.setCustomModelResourceLocation(thisItem, key, variant);
}
}
use of gnu.trove.map.hash.TIntObjectHashMap in project cogcomp-nlp by CogComp.
the class TextAnnotation method getSpansMatching.
public List<IntPair> getSpansMatching(String text) {
if (allSpans == null) {
synchronized (this) {
if (allSpans == null) {
this.allSpans = TCollections.synchronizedMap(new TIntObjectHashMap<ArrayList<IntPair>>());
/**
* creates a hash for each contiguous substring, and creates an entry for it in
* allSpans NOTE: spans previously used "at-the-end" indexing but then the
* offsets won't agree with actual constituents, so CHANGED IT 2016/05/11. MS
*/
for (int start = 0; start < this.size() - 1; start++) {
StringBuilder sb = new StringBuilder();
for (int end = start; end < this.size(); end++) {
String token = tokens[end];
token = token.replaceAll("``", "\"").replaceAll("''", "\"");
token = SentenceUtils.convertFromPTBBrackets(token);
sb.append(token).append(" ");
int hash = sb.toString().trim().hashCode();
if (!allSpans.containsKey(hash))
allSpans.put(hash, new ArrayList<IntPair>());
List<IntPair> list = allSpans.get(hash);
list.add(new IntPair(start, end + 1));
}
}
}
}
}
int hashCode = text.trim().hashCode();
int length = text.split("\\s+").length;
List<IntPair> list = allSpans.get(hashCode);
if (list == null)
list = new ArrayList<>();
return list;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method getSimulationCoordinates.
/**
* Gets the coordinates for the current simulation. This extract all the results in memory into a
* list per frame and is cached for the simulation Id.
*
* @return the coordinates
*/
private TIntObjectHashMap<PsfSpot[]> getSimulationCoordinates() {
Pair<Integer, TIntObjectHashMap<PsfSpot[]>> coords = coordinateCache.get();
if (coords.getKey() != simulationParameters.id) {
// Always use float coordinates.
// The Worker adds a pixel offset for the spot coordinates.
final TIntObjectHashMap<List<Coordinate>> coordinates = ResultsMatchCalculator.getCoordinates(results, false);
// Spot PSFs may overlap so we must determine the amount of signal overlap and amplitude
// effect for each spot...
final int nThreads = Prefs.getThreads();
final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
final List<OverlapWorker> workers = new LinkedList<>();
final List<Thread> threads = new LinkedList<>();
final Ticker overlapTicker = ImageJUtils.createTicker(coordinates.size(), nThreads, "Computing PSF overlap ...");
for (int i = 0; i < nThreads; i++) {
final OverlapWorker worker = new OverlapWorker(jobs, coordinates, overlapTicker);
final Thread t = new Thread(worker);
workers.add(worker);
threads.add(t);
t.start();
}
// Process the frames
coordinates.forEachKey(value -> {
put(jobs, value);
return true;
});
// Finish all the worker threads by passing in a null job
for (int i = 0; i < threads.size(); i++) {
put(jobs, -1);
}
// Wait for all to finish
final TIntObjectHashMap<PsfSpot[]> actualCoordinates = new TIntObjectHashMap<>();
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
}
actualCoordinates.putAll(workers.get(i).coordinates);
}
threads.clear();
// For testing
final SimpleRegression regression = new SimpleRegression(false);
for (final PsfSpot[] spots : actualCoordinates.valueCollection()) {
for (final PsfSpot spot : spots) {
regression.addData(spot.getAmplitude(), calculator.getAmplitude(spot.getPeakResult().getParameters()));
}
}
ImageJUtils.log("PixelAmplitude vs Amplitude = %f, slope=%f, n=%d", regression.getR(), regression.getSlope(), regression.getN());
ImageJUtils.finished();
coords = Pair.of(simulationParameters.id, actualCoordinates);
coordinateCache.set(coords);
}
return coords.getRight();
}
use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method getCoordinates.
private static TIntObjectHashMap<UniqueIdPeakResult[]> getCoordinates(MemoryPeakResults results) {
final TIntObjectHashMap<UniqueIdPeakResult[]> coords = new TIntObjectHashMap<>();
if (results.size() > 0) {
// Do not use HashMap directly to build the coords object since there
// will be many calls to getEntry(). Instead sort the results and use
// a new list for each time point
results.sort();
final Counter uniqueId = new Counter();
final FrameCounter counter = new FrameCounter();
final LocalList<PeakResult> tmp = new LocalList<>();
// Add the results to the lists
results.forEach((PeakResultProcedure) result -> {
if (counter.advanceAndReset(result.getFrame()) && !tmp.isEmpty()) {
coords.put(counter.previousFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
tmp.clear();
}
tmp.add(new UniqueIdPeakResult(tmp.size(), uniqueId.getAndIncrement(), result));
});
if (!tmp.isEmpty()) {
coords.put(counter.currentFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
}
}
return coords;
}
Aggregations