use of gnu.trove.set.TLongSet in project gridss by PapenfussLab.
the class DeBruijnGraphBase method debugPrintPaths.
public String debugPrintPaths() {
Map<Long, Integer> contigLookup = Maps.newHashMap();
TLongSet remaining = new TLongHashSet(kmers.keySet());
List<LinkedList<Long>> paths = Lists.newArrayList();
int contig = 0;
// enumerate the paths
while (!remaining.isEmpty()) {
contig++;
LinkedList<Long> path = new LinkedList<Long>();
path.add(remaining.iterator().next());
remaining.remove(path.getFirst());
contigLookup.put(path.getFirst(), contig);
for (List<Long> adj = nextStates(path.getLast(), null, null); adj.size() == 1 && prevStates(adj.get(0), null, null).size() <= 1; adj = nextStates(path.getLast(), null, null)) {
contigLookup.put(adj.get(0), contig);
path.addLast(adj.get(0));
remaining.remove(adj.get(0));
}
for (List<Long> adj = prevStates(path.getFirst(), null, null); adj.size() == 1 && nextStates(adj.get(0), null, null).size() <= 1; adj = prevStates(path.getFirst(), null, null)) {
contigLookup.put(adj.get(0), contig);
path.addFirst(adj.get(0));
remaining.remove(adj.get(0));
}
paths.add(path);
}
return debugPrintPaths(paths, contigLookup);
}
use of gnu.trove.set.TLongSet in project Osmand by osmandapp.
the class MapRenderRepositories method loadVectorData.
private boolean loadVectorData(QuadRect dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) {
double cBottomLatitude = dataBox.bottom;
double cTopLatitude = dataBox.top;
double cLeftLongitude = dataBox.left;
double cRightLongitude = dataBox.right;
long now = System.currentTimeMillis();
// to clear previous objects
System.gc();
ArrayList<BinaryMapDataObject> tempResult = new ArrayList<BinaryMapDataObject>();
ArrayList<BinaryMapDataObject> basemapResult = new ArrayList<BinaryMapDataObject>();
int[] count = new int[] { 0 };
boolean[] ocean = new boolean[] { false };
boolean[] land = new boolean[] { false };
List<BinaryMapDataObject> coastLines = new ArrayList<BinaryMapDataObject>();
List<BinaryMapDataObject> basemapCoastLines = new ArrayList<BinaryMapDataObject>();
int leftX = MapUtils.get31TileNumberX(cLeftLongitude);
int rightX = MapUtils.get31TileNumberX(cRightLongitude);
int bottomY = MapUtils.get31TileNumberY(cBottomLatitude);
int topY = MapUtils.get31TileNumberY(cTopLatitude);
TLongSet ids = new TLongHashSet();
MapIndex mi = readMapObjectsForRendering(zoom, renderingReq, tempResult, basemapResult, ids, count, ocean, land, coastLines, basemapCoastLines, leftX, rightX, bottomY, topY);
int renderRouteDataFile = 0;
if (renderingReq.searchRenderingAttribute("showRoadMapsAttribute")) {
renderRouteDataFile = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
}
if (checkWhetherInterrupted()) {
return false;
}
boolean objectsFromMapSectionRead = tempResult.size() > 0;
if (renderRouteDataFile >= 0 && zoom >= zoomOnlyForBasemaps) {
searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, null);
for (BinaryMapIndexReader c : files.values()) {
// false positive case when we have 2 sep maps Country-roads & Country
if (c.getMapIndexes().size() == 0 || renderRouteDataFile == 1) {
readRouteDataAsMapObjects(searchRequest, c, tempResult, ids);
}
}
log.info(String.format("Route objects %s", tempResult.size() + ""));
}
String coastlineTime = "";
boolean addBasemapCoastlines = true;
boolean emptyData = zoom > zoomOnlyForBasemaps && tempResult.isEmpty() && coastLines.isEmpty();
boolean basemapMissing = zoom <= zoomOnlyForBasemaps && basemapCoastLines.isEmpty() && mi == null;
boolean detailedLandData = zoom >= zoomForBaseRouteRendering && tempResult.size() > 0 && objectsFromMapSectionRead;
if (!coastLines.isEmpty()) {
long ms = System.currentTimeMillis();
boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom, basemapCoastLines.isEmpty(), true, tempResult);
addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= zoomOnlyForBasemaps;
coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )";
} else {
addBasemapCoastlines = !detailedLandData;
}
if (addBasemapCoastlines) {
long ms = System.currentTimeMillis();
boolean coastlinesWereAdded = processCoastlines(basemapCoastLines, leftX, rightX, bottomY, topY, zoom, true, true, tempResult);
addBasemapCoastlines = !coastlinesWereAdded;
coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )";
}
if (addBasemapCoastlines && mi != null) {
int[] coordinates = new int[] { leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, topY };
BinaryMapDataObject o = new BinaryMapDataObject(-1, coordinates, new int[0][], RenderingRulesStorage.POLYGON_RULES, true, new int[] { ocean[0] && !land[0] ? mi.coastlineEncodingType : (mi.landEncodingType) }, null);
o.setMapIndex(mi);
tempResult.add(o);
}
if (emptyData || basemapMissing) {
// message
MapIndex mapIndex;
if (!tempResult.isEmpty()) {
mapIndex = tempResult.get(0).getMapIndex();
} else {
mapIndex = new MapIndex();
mapIndex.initMapEncodingRule(0, 1, "natural", "coastline");
mapIndex.initMapEncodingRule(0, 2, "name", "");
}
}
if (zoom <= zoomOnlyForBasemaps || emptyData) {
tempResult.addAll(basemapResult);
}
if (count[0] > 0) {
log.info(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"BLat=%s, TLat=%s, LLong=%s, RLong=%s, zoom=%s", cBottomLatitude, cTopLatitude, cLeftLongitude, cRightLongitude, zoom));
// $NON-NLS-1$
log.info(String.format("Searching: %s ms %s (%s results found)", System.currentTimeMillis() - now, coastlineTime, count[0]));
}
cObjects = tempResult;
cObjectsBox = dataBox;
cObjectsZoom = zoom;
return true;
}
use of gnu.trove.set.TLongSet in project GregTech by GregTechCE.
the class CachedGridEntry method getGeneratedBlocks.
@Override
public Collection<IBlockState> getGeneratedBlocks(OreDepositDefinition definition, int chunkX, int chunkZ) {
long chunkId = (long) chunkX << 32 | chunkZ & 0xFFFFFFFFL;
ChunkDataEntry chunkDataEntry = dataByChunkPos.get(chunkId);
if (chunkDataEntry != null) {
TLongSet longSet = chunkDataEntry.generatedBlocksSet.get(definition);
ArrayList<IBlockState> blockStates = new ArrayList<>();
TLongIterator iterator = longSet.iterator();
while (iterator.hasNext()) blockStates.add(Block.getStateById((int) iterator.next()));
return blockStates;
}
return Collections.emptyList();
}
use of gnu.trove.set.TLongSet in project MantaroBot by Mantaro.
the class ShardedMantaro method startUpdaters.
private void startUpdaters() {
Async.task("Carbonitex post task", carbonitex::handle, 30, TimeUnit.MINUTES);
if (config.dbotsorgToken != null) {
Async.task("dbots.org update thread", () -> {
try {
long count = MantaroBot.getInstance().getGuildCache().size();
int[] shards = MantaroBot.getInstance().getShardList().stream().mapToInt(shard -> (int) shard.getGuildCache().size()).toArray();
discordBotsAPI.postStats(shards);
log.debug("Updated server count ({}) for discordbots.org", count);
} catch (Exception ignored) {
}
}, 1, TimeUnit.HOURS);
Async.task("discordbots.org upvotes task", () -> {
if (config.dbotsorgToken == null)
return;
try {
Request request = new Request.Builder().url("https://discordbots.org/api/bots/213466096718708737/votes?onlyids=1").addHeader("Authorization", config.dbotsorgToken).build();
Response r = Utils.httpClient.newCall(request).execute();
ResponseBody body = r.body();
if (body == null)
return;
// It's definitely String.
@SuppressWarnings("unchecked") List<String> upvoters = objectMapper.readValue(body.string(), List.class);
List<Long> upvotersLong = upvoters.stream().map(Long::parseLong).distinct().collect(Collectors.toList());
TLongSet set = new TLongHashSet();
set.addAll(upvotersLong);
discordBotsUpvoters = new TUnmodifiableLongSet(set);
r.close();
} catch (Exception ignored) {
}
}, 5, TimeUnit.MINUTES);
} else {
log.warn("discordbots.org token not set in config, cannot start posting stats!");
}
String dbotsToken = config.dbotsToken;
if (dbotsToken != null) {
Async.task("bots.discord.pw update Thread", () -> {
try {
long count = MantaroBot.getInstance().getGuildCache().size();
RequestBody body = RequestBody.create(JSON, new JSONObject().put("server_count", count).toString());
Request request = new Request.Builder().url("https://bots.discord.pw/api/bots/213466096718708737/stats").addHeader("User-Agent", MantaroInfo.USER_AGENT).addHeader("Authorization", dbotsToken).addHeader("Content-Type", "application/json").post(body).build();
Utils.httpClient.newCall(request).execute().close();
log.debug("Updated server count for bots.discord.pw");
} catch (Exception ignored) {
}
}, 1, TimeUnit.HOURS);
}
for (MantaroShard shard : getShards()) {
shard.updateStatus();
}
}
use of gnu.trove.set.TLongSet in project OpenTripPlanner by opentripplanner.
the class HashGridSpatialIndex method insert.
public final void insert(LineString geom, final Object item) {
Coordinate[] coord = geom.getCoordinates();
final TLongSet keys = new TLongHashSet(coord.length * 8);
for (int i = 0; i < coord.length - 1; i++) {
// TODO Cut the segment if longer than bin size
// to reduce the number of wrong bins
Envelope env = new Envelope(coord[i], coord[i + 1]);
visit(env, true, new BinVisitor<T>() {
@Override
public boolean visit(List<T> bin, long mapKey) {
keys.add(mapKey);
return false;
}
});
}
keys.forEach(new TLongProcedure() {
@SuppressWarnings("unchecked")
@Override
public boolean execute(long key) {
// Note: bins have been initialized in the previous visit
bins.get(key).add((T) item);
nEntries++;
return true;
}
});
nObjects++;
}
Aggregations