Search in sources :

Example 1 with TLongSet

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);
}
Also used : TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) LinkedList(java.util.LinkedList)

Example 2 with TLongSet

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;
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex)

Example 3 with TLongSet

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();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TLongSet(gnu.trove.set.TLongSet) TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongIterator(gnu.trove.iterator.TLongIterator)

Example 4 with TLongSet

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();
    }
}
Also used : MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) Getter(lombok.Getter) PostLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PostLoadEvent) Async(br.com.brjdevs.java.utils.async.Async) Utils(net.kodehawa.mantarobot.utils.Utils) SHARD_FETCH_FAILURE(net.kodehawa.mantarobot.utils.ShutdownCodes.SHARD_FETCH_FAILURE) LoadState(net.kodehawa.mantarobot.core.LoadState) ICommandProcessor(net.kodehawa.mantarobot.core.processor.core.ICommandProcessor) ArrayList(java.util.ArrayList) MantaroBot(net.kodehawa.mantarobot.MantaroBot) JSONObject(org.json.JSONObject) okhttp3(okhttp3) TLongHashSet(gnu.trove.set.hash.TLongHashSet) SnowflakeCacheView(net.dv8tion.jda.core.utils.cache.SnowflakeCacheView) Collector(java.util.stream.Collector) MantaroCore(net.kodehawa.mantarobot.core.MantaroCore) Config(net.kodehawa.mantarobot.data.Config) PostingException(com.github.natanbc.discordbotsapi.PostingException) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) TLongSet(gnu.trove.set.TLongSet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SentryHelper(net.kodehawa.mantarobot.utils.SentryHelper) Collectors(java.util.stream.Collectors) DiscordBotsAPI(com.github.natanbc.discordbotsapi.DiscordBotsAPI) MantaroEventManager(net.kodehawa.mantarobot.core.MantaroEventManager) TimeUnit(java.util.concurrent.TimeUnit) ShardWatcher(net.kodehawa.mantarobot.core.shard.watcher.ShardWatcher) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TUnmodifiableLongSet(gnu.trove.impl.unmodifiable.TUnmodifiableLongSet) Carbonitex(net.kodehawa.mantarobot.services.Carbonitex) MantaroData(net.kodehawa.mantarobot.data.MantaroData) LogUtils(net.kodehawa.mantarobot.log.LogUtils) JSONArray(org.json.JSONArray) PostingException(com.github.natanbc.discordbotsapi.PostingException) JSONObject(org.json.JSONObject) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) TUnmodifiableLongSet(gnu.trove.impl.unmodifiable.TUnmodifiableLongSet)

Example 5 with TLongSet

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++;
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope) TLongProcedure(gnu.trove.procedure.TLongProcedure) Coordinate(com.vividsolutions.jts.geom.Coordinate) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Aggregations

TLongSet (gnu.trove.set.TLongSet)6 TLongHashSet (gnu.trove.set.hash.TLongHashSet)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 Async (br.com.brjdevs.java.utils.async.Async)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DiscordBotsAPI (com.github.natanbc.discordbotsapi.DiscordBotsAPI)1 PostingException (com.github.natanbc.discordbotsapi.PostingException)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 YouTube (com.google.api.services.youtube.YouTube)1 SearchListResponse (com.google.api.services.youtube.model.SearchListResponse)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1