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);
}
}
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);
}
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));
}
}
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;
}
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;
}
Aggregations