Search in sources :

Example 21 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project Osmand by osmandapp.

the class MapRenderRepositories method readRouteDataAsMapObjects.

private void readRouteDataAsMapObjects(SearchRequest<BinaryMapDataObject> sr, BinaryMapIndexReader c, final ArrayList<BinaryMapDataObject> tempResult, final TLongSet ids) {
    final boolean basemap = c.isBasemap();
    try {
        for (RouteRegion reg : c.getRoutingIndexes()) {
            List<RouteSubregion> parent = sr.getZoom() < 15 ? reg.getBaseSubregions() : reg.getSubregions();
            List<RouteSubregion> searchRouteIndexTree = c.searchRouteIndexTree(sr, parent);
            final MapIndex nmi = new MapIndex();
            c.loadRouteIndexData(searchRouteIndexTree, new ResultMatcher<RouteDataObject>() {

                @Override
                public boolean publish(RouteDataObject r) {
                    if (basemap) {
                        renderedState |= 1;
                    } else {
                        renderedState |= 2;
                    }
                    if (checkForDuplicateObjectIds && !basemap) {
                        if (ids.contains(r.getId()) && r.getId() > 0) {
                            // do not add object twice
                            return false;
                        }
                        ids.add(r.getId());
                    }
                    int[] coordinantes = new int[r.getPointsLength() * 2];
                    int[] roTypes = r.getTypes();
                    for (int k = 0; k < roTypes.length; k++) {
                        int type = roTypes[k];
                        registerMissingType(nmi, r, type);
                    }
                    for (int k = 0; k < coordinantes.length / 2; k++) {
                        coordinantes[2 * k] = r.getPoint31XTile(k);
                        coordinantes[2 * k + 1] = r.getPoint31YTile(k);
                    }
                    BinaryMapDataObject mo = new BinaryMapDataObject(r.getId(), coordinantes, new int[0][], RenderingRulesStorage.LINE_RULES, true, roTypes, null);
                    TIntObjectHashMap<String> names = r.getNames();
                    if (names != null) {
                        TIntObjectIterator<String> it = names.iterator();
                        while (it.hasNext()) {
                            it.advance();
                            registerMissingType(nmi, r, it.key());
                            mo.putObjectName(it.key(), it.value());
                        }
                    }
                    mo.setMapIndex(nmi);
                    tempResult.add(mo);
                    return false;
                }

                private void registerMissingType(final MapIndex nmi, RouteDataObject r, int type) {
                    if (!nmi.isRegisteredRule(type)) {
                        RouteTypeRule rr = r.region.quickGetEncodingRule(type);
                        String tag = rr.getTag();
                        int additional = ("highway".equals(tag) || "route".equals(tag) || "railway".equals(tag) || "aeroway".equals(tag) || "aerialway".equals(tag)) ? 0 : 1;
                        nmi.initMapEncodingRule(additional, type, rr.getTag(), rr.getValue());
                    }
                }

                @Override
                public boolean isCancelled() {
                    return !interrupted;
                }
            });
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        log.debug("Search failed " + c.getRegionNames(), e);
    }
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) TIntObjectIterator(gnu.trove.iterator.TIntObjectIterator) RouteTypeRule(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule) IOException(java.io.IOException) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex)

Example 22 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project spf4j by zolyfarkas.

the class Converter method convert.

public static SampleNode convert(final Iterator<ASample> samples) {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    while (samples.hasNext()) {
        ASample asmp = samples.next();
        SampleNode sn = new SampleNode(asmp.count, new THashMap<Method, SampleNode>(4));
        SampleNode parent = index.get(asmp.parentId);
        if (parent != null) {
            AMethod method = asmp.getMethod();
            Method m = Method.getMethod(method.declaringClass, method.getName());
            final Map<Method, SampleNode> subNodes = parent.getSubNodes();
            if (subNodes == null) {
                throw new IllegalStateException("Bug, state " + index + "; at node " + asmp);
            }
            subNodes.put(m, sn);
        }
        index.put(asmp.id, sn);
    }
    return index.get(0);
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ASample(org.spf4j.ssdump2.avro.ASample) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.Method) AMethod(org.spf4j.ssdump2.avro.AMethod) AMethod(org.spf4j.ssdump2.avro.AMethod)

Example 23 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project GregTech by GregTechCE.

the class PipeNet method deserializeAllNodeList.

protected void deserializeAllNodeList(NBTTagCompound compound) {
    NBTTagList allNodesList = compound.getTagList("NodeIndexes", NBT.TAG_COMPOUND);
    NBTTagList wirePropertiesList = compound.getTagList("WireProperties", NBT.TAG_COMPOUND);
    TIntObjectMap<NodeDataType> readProperties = new TIntObjectHashMap<>();
    for (int i = 0; i < wirePropertiesList.tagCount(); i++) {
        NBTTagCompound propertiesTag = wirePropertiesList.getCompoundTagAt(i);
        int wirePropertiesIndex = propertiesTag.getInteger("index");
        NodeDataType nodeData = readNodeData(propertiesTag);
        readProperties.put(wirePropertiesIndex, nodeData);
    }
    for (int i = 0; i < allNodesList.tagCount(); i++) {
        NBTTagCompound nodeTag = allNodesList.getCompoundTagAt(i);
        int x = nodeTag.getInteger("x");
        int y = nodeTag.getInteger("y");
        int z = nodeTag.getInteger("z");
        int wirePropertiesIndex = nodeTag.getInteger("index");
        BlockPos blockPos = new BlockPos(x, y, z);
        NodeDataType nodeData = readProperties.get(wirePropertiesIndex);
        int blockedConnections = nodeTag.getInteger("blocked");
        int mark = nodeTag.getInteger("mark");
        boolean isNodeActive = nodeTag.getBoolean("active");
        addNodeSilently(blockPos, new Node<>(nodeData, blockedConnections, mark, isNodeActive));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos)

Example 24 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project scheduler by btrplace.

the class StaticRoutingConverter method fromJSON.

@Override
public StaticRouting fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    Network v = Network.get(mo);
    TIntObjectMap<Link> idToLink = new TIntObjectHashMap<>();
    for (Link l : v.getLinks()) {
        idToLink.put(l.id(), l);
    }
    StaticRouting r = new StaticRouting();
    checkKeys(o, ROUTES_LABEL);
    JSONArray a = (JSONArray) o.get(ROUTES_LABEL);
    for (Object ao : a) {
        StaticRouting.NodesMap nm = nodesMapFromJSON(mo, (JSONObject) ((JSONObject) ao).get("nodes_map"));
        Map<Link, Boolean> links = new LinkedHashMap<>();
        JSONArray aoa = (JSONArray) ((JSONObject) ao).get("links");
        for (Object aoao : aoa) {
            links.put(idToLink.get(requiredInt((JSONObject) aoao, "link")), Boolean.valueOf(requiredString((JSONObject) aoao, "direction")));
        }
        r.setStaticRoute(nm, links);
    }
    return r;
}
Also used : JSONObject(net.minidev.json.JSONObject) StaticRouting(org.btrplace.model.view.network.StaticRouting) Network(org.btrplace.model.view.network.Network) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) Link(org.btrplace.model.view.network.Link) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project cogcomp-nlp by CogComp.

the class GazetteerViewGenerator method hashAllSpans.

private TIntObjectHashMap<ArrayList<IntPair>> hashAllSpans(TextAnnotation ta) {
    TIntObjectHashMap<ArrayList<IntPair>> allSpans = new TIntObjectHashMap<>();
    for (int start = 0; start < ta.size() - 1; start++) {
        int last = Math.min(ta.size(), start + maxLength);
        StringBuilder sb = new StringBuilder();
        for (int end = start; end < last; end++) {
            String token = ta.getToken(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<>());
            List<IntPair> object = allSpans.get(hash);
            object.add(new IntPair(start, end + 1));
        }
    }
    return allSpans;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) IntPair(edu.illinois.cs.cogcomp.core.datastructures.IntPair)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)43 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)12 List (java.util.List)11 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)10 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)9 TIntHashSet (gnu.trove.set.hash.TIntHashSet)8 IJ (ij.IJ)8 Prefs (ij.Prefs)8 PlugIn (ij.plugin.PlugIn)8 TextWindow (ij.text.TextWindow)8 Arrays (java.util.Arrays)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)8 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)8 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)8 TIntProcedure (gnu.trove.procedure.TIntProcedure)7