gnu.trove.map.hash.TLongObjectHashMap Java Examples
The following examples show how to use
gnu.trove.map.hash.TLongObjectHashMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FallingBlocksMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) { FallingBlocksRule rule = this.ruleWithShortestDelay(blockState); if (rule != null) { long tick = match.getTick().tick + rule.delay; TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick); if (blockDisturbers == null) { blockDisturbers = new TLongObjectHashMap<>(); this.blockDisturbersByTick.put(tick, blockDisturbers); } Block block = blockState.getBlock(); if (!blockDisturbers.containsKey(pos)) { blockDisturbers.put(pos, disturber); } } }
Example #2
Source File: ChannelManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
protected Collection<PermOverrideData> getOverrides() { //note: overridesAdd and overridesRem are mutually disjoint TLongObjectHashMap<PermOverrideData> data = new TLongObjectHashMap<>(this.overridesAdd); AbstractChannelImpl<?,?> impl = (AbstractChannelImpl<?,?>) getChannel(); impl.getOverrideMap().forEachEntry((id, override) -> { //removed by not adding them here, this data set overrides the existing one //we can use remove because it will be reset afterwards either way if (!overridesRem.remove(id) && !data.containsKey(id)) data.put(id, new PermOverrideData(override)); return true; }); return data.valueCollection(); }
Example #3
Source File: MemberChunkManager.java From JDA with Apache License 2.0 | 6 votes |
private List<Member> toMembers(DataObject chunk) { EntityBuilder builder = guild.getJDA().getEntityBuilder(); DataArray memberArray = chunk.getArray("members"); TLongObjectMap<DataObject> presences = chunk.optArray("presences").map(it -> builder.convertToUserMap(o -> o.getObject("user").getUnsignedLong("id"), it) ).orElseGet(TLongObjectHashMap::new); List<Member> collect = new ArrayList<>(memberArray.length()); for (int i = 0; i < memberArray.length(); i++) { DataObject json = memberArray.getObject(i); long userId = json.getObject("user").getUnsignedLong("id"); DataObject presence = presences.get(userId); MemberImpl member = builder.createMember(guild, json, null, presence); builder.updateMemberCache(member); collect.add(member); } return collect; }
Example #4
Source File: FallingBlocksMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) { FallingBlocksRule rule = this.ruleWithShortestDelay(blockState); if(rule != null) { long tick = this.getMatch().getClock().now().tick + rule.delay; TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick); if(blockDisturbers == null) { blockDisturbers = new TLongObjectHashMap<>(); this.blockDisturbersByTick.put(tick, blockDisturbers); } Block block = blockState.getBlock(); if(!blockDisturbers.containsKey(pos)) { blockDisturbers.put(pos, disturber); } } }
Example #5
Source File: FallingBlocksMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * Make any unsupported blocks fall that are disturbed for the current tick */ private void fallCheck() { this.visitsWorstTick = Math.max(this.visitsWorstTick, this.visitsThisTick); this.visitsThisTick = 0; World world = this.getMatch().getWorld(); TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.remove(this.getMatch().getClock().now().tick); if(blockDisturbers == null) return; TLongSet supported = new TLongHashSet(); TLongSet unsupported = new TLongHashSet(); TLongObjectMap<ParticipantState> fallsByBreaker = new TLongObjectHashMap<>(); try { while(!blockDisturbers.isEmpty()) { long pos = blockDisturbers.keySet().iterator().next(); ParticipantState breaker = blockDisturbers.remove(pos); // Search down for the first block that can actually fall for(;;) { long below = neighborPos(pos, BlockFace.DOWN); if(!Materials.isColliding(blockAt(world, below).getType())) break; blockDisturbers.remove(pos); // Remove all the blocks we find along the way pos = below; } // Check if the block needs to fall, if it isn't already falling if(!fallsByBreaker.containsKey(pos) && !this.isSupported(pos, supported, unsupported)) { fallsByBreaker.put(pos, breaker); } } } catch(MaxSearchVisitsExceeded ex) { this.logError(ex); } for(TLongObjectIterator<ParticipantState> iter = fallsByBreaker.iterator(); iter.hasNext();) { iter.advance(); this.fall(iter.key(), iter.value()); } }
Example #6
Source File: CommitCanvasN5.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <I extends IntegerType<I> & NativeType<I>> void writeBlocksLabelIntegerType( final RandomAccessibleInterval<UnsignedLongType> canvas, final long[] blocks, final DatasetSpec datasetSpec, final BlockSpec blockSpec, final TLongObjectHashMap<BlockDiff> blockDiff) throws IOException { final RandomAccessibleInterval<I> highestResolutionData = N5Utils.open(datasetSpec.container, datasetSpec.dataset); final I i = Util.getTypeFromInterval(highestResolutionData).createVariable(); for (final long blockId : blocks) { blockSpec.fromLinearIndex(blockId); final RandomAccessibleInterval<Pair<I, UnsignedLongType>> backgroundWithCanvas = Views.interval(Views.pair(highestResolutionData, canvas), blockSpec.asInterval()); final RandomAccessibleInterval<I> mergedData = Converters.convert(backgroundWithCanvas, (s, t) -> pickFirstIfSecondIsInvalid(s.getA(), s.getB(), t), i.createVariable()); N5Utils.saveBlock(mergedData, datasetSpec.container, datasetSpec.dataset, datasetSpec.attributes, blockSpec.pos); blockDiff.put(blockId, createBlockDiffFromCanvasIntegerType(Views.iterable(backgroundWithCanvas))); } }
Example #7
Source File: CommitCanvasN5.java From paintera with GNU General Public License v2.0 | 6 votes |
private static void writeBlocksLabelMultisetType( final RandomAccessibleInterval<UnsignedLongType> canvas, final long[] blocks, final DatasetSpec datasetSpec, final BlockSpec blockSpec, final TLongObjectHashMap<BlockDiff> blockDiff) throws IOException { final RandomAccessibleInterval<LabelMultisetType> highestResolutionData = N5LabelMultisets.openLabelMultiset(datasetSpec.container, datasetSpec.dataset); for (final long blockId : blocks) { blockSpec.fromLinearIndex(blockId); final IntervalView<Pair<LabelMultisetType, UnsignedLongType>> backgroundWithCanvas = Views.interval(Views.pair(highestResolutionData, canvas), blockSpec.asInterval()); final int numElements = (int) Intervals.numElements(backgroundWithCanvas); final byte[] byteData = LabelUtils.serializeLabelMultisetTypes(new BackgroundCanvasIterable(Views.flatIterable(backgroundWithCanvas)), numElements); final ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(Intervals.dimensionsAsIntArray(backgroundWithCanvas), blockSpec.pos, byteData); datasetSpec.container.writeBlock(datasetSpec.dataset, datasetSpec.attributes, dataBlock); blockDiff.put(blockId, createBlockDiffFromCanvas(backgroundWithCanvas)); } }
Example #8
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 6 votes |
private SectionInfo createSectionInfo(final PainteraBaseView paintera) { Interval selectionSourceBoundingBox = null; for (final TLongObjectIterator<SelectedObjectInfo> it = selectedObjects.iterator(); it.hasNext();) { it.advance(); if (selectionSourceBoundingBox == null) selectionSourceBoundingBox = it.value().sourceBoundingBox; else selectionSourceBoundingBox = Intervals.union(selectionSourceBoundingBox, it.value().sourceBoundingBox); } final AffineTransform3D globalTransform = new AffineTransform3D(); paintera.manager().getTransform(globalTransform); return new SectionInfo( mask, globalTransform, getMaskDisplayTransformIgnoreScaling(SHAPE_INTERPOLATION_SCALE_LEVEL), selectionSourceBoundingBox, new TLongObjectHashMap<>(selectedObjects) ); }
Example #9
Source File: ProcessLinkSearchMap.java From olca-app with Mozilla Public License 2.0 | 5 votes |
public ProcessLinkSearchMap(Collection<ProcessLink> links) { providerIndex = new TLongObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1L); connectionIndex = new TLongObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1L); data = new ArrayList<>(links); for (int i = 0; i < data.size(); i++) { ProcessLink link = data.get(i); index(link.providerId, i, providerIndex); index(link.processId, i, connectionIndex); } }
Example #10
Source File: TcpChannelHub.java From Chronicle-Network with Apache License 2.0 | 5 votes |
TcpSocketConsumer() { if (DEBUG_ENABLED) Jvm.debug().on(TcpChannelHub.class, "constructor remoteAddress=" + socketAddressSupplier); service = newCachedThreadPool( new NamedThreadFactory(threadName(), true)); final TLongObjectHashMap<Object> longMap = new TLongObjectHashMap<>(32); // Prevent excessive array creation upon removals longMap.setAutoCompactionFactor(0); map = TCollections.synchronizedMap(longMap); start(); }
Example #11
Source File: ProcessLinkSearchMap.java From olca-app with Mozilla Public License 2.0 | 5 votes |
private List<ProcessLink> getLinks(long processId, TLongObjectHashMap<TIntArrayList> map) { TIntArrayList list = map.get(processId); if (list == null) return Collections.emptyList(); return getLinks(list.iterator()); }
Example #12
Source File: EntityBuilder.java From JDA with Apache License 2.0 | 5 votes |
public TLongObjectMap<DataObject> convertToUserMap(ToLongFunction<DataObject> getId, DataArray array) { TLongObjectMap<DataObject> map = new TLongObjectHashMap<>(); for (int i = 0; i < array.length(); i++) { DataObject obj = array.getObject(i); long userId = getId.applyAsLong(obj); map.put(userId, obj); } return map; }
Example #13
Source File: MutableProcessLinkSearchMap.java From olca-app with Mozilla Public License 2.0 | 5 votes |
private void remove(long id, int index, TLongObjectHashMap<TIntArrayList> map) { TIntArrayList list = map.get(id); if (list == null) return; list.remove(index); if (list.size() == 0) map.remove(id); }
Example #14
Source File: ChannelManagerImpl.java From JDA with Apache License 2.0 | 5 votes |
/** * Creates a new ChannelManager instance * * @param channel * {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} that should be modified * <br>Either {@link net.dv8tion.jda.api.entities.VoiceChannel Voice}- or {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} */ public ChannelManagerImpl(GuildChannel channel) { super(channel.getJDA(), Route.Channels.MODIFY_CHANNEL.compile(channel.getId())); JDA jda = channel.getJDA(); ChannelType type = channel.getType(); this.channel = new SnowflakeReference<>(channel, (channelId) -> jda.getGuildChannelById(type, channelId)); if (isPermissionChecksEnabled()) checkPermissions(); this.overridesAdd = new TLongObjectHashMap<>(); this.overridesRem = new TLongHashSet(); }
Example #15
Source File: EventCache.java From JDA with Apache License 2.0 | 5 votes |
public synchronized void cache(Type type, long triggerId, long responseTotal, DataObject event, CacheConsumer handler) { TLongObjectMap<List<CacheNode>> triggerCache = eventCache.computeIfAbsent(type, k -> new TLongObjectHashMap<>()); List<CacheNode> items = triggerCache.get(triggerId); if (items == null) { items = new LinkedList<>(); triggerCache.put(triggerId, items); } items.add(new CacheNode(responseTotal, event, handler)); }
Example #16
Source File: GuildMembersChunkHandler.java From JDA with Apache License 2.0 | 5 votes |
@Override protected Long handleInternally(DataObject content) { final long guildId = content.getLong("guild_id"); DataArray members = content.getArray("members"); GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId); if (guild != null) { if (api.getClient().getChunkManager().handleChunk(guildId, content)) return null; WebSocketClient.LOG.debug("Received member chunk for guild that is already in cache. GuildId: {} Count: {} Index: {}/{}", guildId, members.length(), content.getInt("chunk_index"), content.getInt("chunk_count")); // Chunk handling EntityBuilder builder = getJDA().getEntityBuilder(); TLongObjectMap<DataObject> presences = content.optArray("presences").map(it -> builder.convertToUserMap(o -> o.getObject("user").getUnsignedLong("id"), it) ).orElseGet(TLongObjectHashMap::new); for (int i = 0; i < members.length(); i++) { DataObject object = members.getObject(i); long userId = object.getObject("user").getUnsignedLong("id"); DataObject presence = presences.get(userId); MemberImpl member = builder.createMember(guild, object, null, presence); builder.updateMemberCache(member); } return null; } getJDA().getGuildSetupController().onMemberChunk(guildId, content); return null; }
Example #17
Source File: GuildSetupNode.java From JDA with Apache License 2.0 | 5 votes |
private void ensureMembers() { expectedMemberCount = partialGuild.getInt("member_count"); members = new TLongObjectHashMap<>(expectedMemberCount); removedMembers = new TLongHashSet(); DataArray memberArray = partialGuild.getArray("members"); if (!getController().getJDA().chunkGuild(id)) { handleMemberChunk(true, memberArray); } else if (memberArray.length() < expectedMemberCount && !requestedChunk) { updateStatus(GuildSetupController.Status.CHUNKING); getController().addGuildForChunking(id, isJoin()); requestedChunk = true; } else if (handleMemberChunk(false, memberArray) && !requestedChunk) { // Discord sent us enough members to satisfy the member_count // but we found duplicates and still didn't reach enough to satisfy the count // in this case we try to do chunking instead // This is caused by lazy guilds and intended behavior according to jake GuildSetupController.log.trace( "Received suspicious members with a guild payload. Attempting to chunk. " + "member_count: {} members: {} actual_members: {} guild_id: {}", expectedMemberCount, memberArray.length(), members.size(), id); members.clear(); updateStatus(GuildSetupController.Status.CHUNKING); getController().addGuildForChunking(id, isJoin()); requestedChunk = true; } }
Example #18
Source File: ReadyHandler.java From JDA with Apache License 2.0 | 5 votes |
@Override protected Long handleInternally(DataObject content) { EntityBuilder builder = getJDA().getEntityBuilder(); DataArray guilds = content.getArray("guilds"); //Make sure we don't have any duplicates here! TLongObjectMap<DataObject> distinctGuilds = new TLongObjectHashMap<>(); for (int i = 0; i < guilds.length(); i++) { DataObject guild = guilds.getObject(i); long id = guild.getUnsignedLong("id"); DataObject previous = distinctGuilds.put(id, guild); if (previous != null) WebSocketClient.LOG.warn("Found duplicate guild for id {} in ready payload", id); } DataObject selfJson = content.getObject("user"); builder.createSelfUser(selfJson); if (getJDA().getGuildSetupController().setIncompleteCount(distinctGuilds.size())) { distinctGuilds.forEachEntry((id, guild) -> { getJDA().getGuildSetupController().onReady(id, guild); return true; }); } handleReady(content); return null; }
Example #19
Source File: WidgetUtil.java From JDA with Apache License 2.0 | 5 votes |
/** * Constructs an unavailable Widget */ private Widget(long guildId) { isAvailable = false; id = guildId; name = null; invite = null; channels = new TLongObjectHashMap<>(); members = new TLongObjectHashMap<>(); }
Example #20
Source File: AirUtils.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private static void stopMusic(AudioUtils audioUtils, ShardManager manager) { final TLongObjectMap<GuildMusicManager> temp = new TLongObjectHashMap<>(audioUtils.getMusicManagers()); for (final long key : temp.keys()) { final Guild guild = manager.getGuildById(key); if (guild != null) { stopMusic(guild, audioUtils); } } }
Example #21
Source File: HistoryExchangeRates.java From financisto with GNU General Public License v2.0 | 5 votes |
private TLongObjectMap<SortedSet<ExchangeRate>> getMapFor(long fromCurrencyId) { TLongObjectMap<SortedSet<ExchangeRate>> m = rates.get(fromCurrencyId); if (m == null) { m = new TLongObjectHashMap<SortedSet<ExchangeRate>>(); rates.put(fromCurrencyId, m); } return m; }
Example #22
Source File: LatestExchangeRates.java From financisto with GNU General Public License v2.0 | 5 votes |
private TLongObjectMap<ExchangeRate> getMapFor(long fromCurrencyId) { TLongObjectMap<ExchangeRate> m = rates.get(fromCurrencyId); if (m == null) { m = new TLongObjectHashMap<ExchangeRate>(); rates.put(fromCurrencyId, m); } return m; }
Example #23
Source File: CurrencyCache.java From financisto with GNU General Public License v2.0 | 5 votes |
public static synchronized void initialize(EntityManager em) { TLongObjectHashMap<Currency> currencies = new TLongObjectHashMap<Currency>(); Query<Currency> q = em.createQuery(Currency.class); Cursor c = q.execute(); try { while (c.moveToNext()) { Currency currency = EntityManager.loadFromCursor(c, Currency.class); currencies.put(currency.id, currency); } } finally { c.close(); } CURRENCIES.putAll(currencies); }
Example #24
Source File: ChainingTSCPair.java From monsoon with BSD 3-Clause "New" or "Revised" License | 4 votes |
public TsvChain(@NonNull DateTime initTs, @NonNull TimeSeriesValue initTsv) { final TLongObjectHashMap<TimeSeriesValue> tail = new TLongObjectHashMap<>(); tail.put(initTs.getMillis(), initTsv); tailRefForAccess = new SoftReference<>(tail); tailRefForUpdate = new WeakReference<>(tail); }
Example #25
Source File: ChannelUpdateHandler.java From JDA with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") private void applyPermissions(AbstractChannelImpl<?,?> channel, DataArray permOverwrites) { TLongObjectMap<PermissionOverride> currentOverrides = new TLongObjectHashMap<>(channel.getOverrideMap()); List<IPermissionHolder> changed = new ArrayList<>(currentOverrides.size()); Guild guild = channel.getGuild(); for (int i = 0; i < permOverwrites.length(); i++) { DataObject overrideJson = permOverwrites.getObject(i); long id = overrideJson.getUnsignedLong("id", 0); if (handlePermissionOverride(currentOverrides.remove(id), overrideJson, id, channel)) addPermissionHolder(changed, guild, id); } currentOverrides.forEachValue(override -> { channel.getOverrideMap().remove(override.getIdLong()); addPermissionHolder(changed, guild, override.getIdLong()); api.handleEvent( new PermissionOverrideDeleteEvent( api, responseNumber, channel, override)); return true; }); if (changed.isEmpty()) return; switch (channel.getType()) { case CATEGORY: api.handleEvent( new CategoryUpdatePermissionsEvent( api, responseNumber, (Category) channel, changed)); break; case STORE: api.handleEvent( new StoreChannelUpdatePermissionsEvent( api, responseNumber, (StoreChannel) channel, changed)); break; case VOICE: api.handleEvent( new VoiceChannelUpdatePermissionsEvent( api, responseNumber, (VoiceChannel) channel, changed)); break; case TEXT: api.handleEvent( new TextChannelUpdatePermissionsEvent( api, responseNumber, (TextChannel) channel, changed)); break; } }
Example #26
Source File: TinkerGraph.java From tinkergraph-gremlin with Apache License 2.0 | 4 votes |
private void initEmptyElementCollections() { vertices = new TLongObjectHashMap<>(); edges = new TLongObjectHashMap<>(); verticesByLabel = new THashMap<>(100); edgesByLabel = new THashMap<>(100); }
Example #27
Source File: PartitionEquivalences.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public PartitionEquivalences() { partitionHashes = new TLongObjectHashMap<>(); observedPartitions = new THashSet<>(); reversedMapping = new THashMap<>(); }
Example #28
Source File: SparseMatrixT.java From fnlp with GNU Lesser General Public License v3.0 | 4 votes |
public SparseMatrixT(){ vector = new TLongObjectHashMap<T>(100,0.8f); }
Example #29
Source File: SparseMatrixT.java From fnlp with GNU Lesser General Public License v3.0 | 4 votes |
public SparseMatrixT<T> clone(){ SparseMatrixT<T> mat = new SparseMatrixT<T>(); mat.dim = this.dim; mat.vector = new TLongObjectHashMap<T>(vector); return mat; }
Example #30
Source File: SparseMatrix.java From fnlp with GNU Lesser General Public License v3.0 | 4 votes |
public SparseMatrix(){ vector = new TLongObjectHashMap<T>(100,0.8f); }