@Override public Iterable<Neighbor> getCandidateNeighbors(final long user, LongSet items) { Long2DoubleMap urs = rvDAO.userRatingVector(user); if (urs.isEmpty()) { return Collections.emptyList(); } final Long2DoubleMap normed = similarityNormalizer.makeTransformation(user, urs) .apply(urs); assert normed != null; LongCollection qset = items; if (normed.size() < qset.size()) { qset = normed.keySet(); } final LongSet candidates = new LongOpenHashSet(); for (LongIterator iter = qset.iterator(); iter.hasNext();) { final long item = iter.nextLong(); LongSet users = snapshot.getItemUsers(item); if (users != null) { candidates.addAll(users); } } candidates.remove(user); logger.debug("Found {} candidate neighbors for user {}", candidates.size(), user); return new Iterable<Neighbor>() { @Override public Iterator<Neighbor> iterator() { return new NeighborIterator(user, normed, candidates); } }; }
/** * Removes an element from this set. * * <p> * This method is inherited from the type-specific collection this type-specific * set is based on, but it should not used as this interface reinstates * {@code remove()} as removal method. * * @deprecated Please use {@code remove()} instead. */ @Deprecated @Override default boolean rem(long k) { return remove(k); } }
/** * Get the IDs of the candidate neighbors for a user. * @param user The user. * @param userItems The user's rated items. * @param targetItems The set of target items. * @return The set of IDs of candidate neighbors. */ private LongSet findCandidateNeighbors(long user, LongSet userItems, LongCollection targetItems) { LongSet users = new LongOpenHashSet(100); LongIterator items; if (userItems.size() < targetItems.size()) { items = userItems.iterator(); } else { items = targetItems.iterator(); } while (items.hasNext()) { LongSet iusers = dao.query(CommonTypes.RATING) .withAttribute(CommonAttributes.ITEM_ID, items.nextLong()) .valueSet(CommonAttributes.USER_ID); if (iusers != null) { users.addAll(iusers); } } users.remove(user); return users; }
public void resetQueuedChunks() { if (!this.entity.getChunkSendQueue().isEmpty()) { for (ChunkAdapter adapter : this.entity.getChunkSendQueue()) { long hash = CoordinateUtils.toLong(adapter.getX(), adapter.getZ()); this.loadingChunks.remove(hash); } } this.entity.getChunkSendQueue().clear(); }
@Override public Iterable<Neighbor> getCandidateNeighbors(final long user, LongSet items) { Long2DoubleMap urs = rvDAO.userRatingVector(user); if (urs.isEmpty()) { return Collections.emptyList(); } final Long2DoubleMap normed = similarityNormalizer.makeTransformation(user, urs) .apply(urs); assert normed != null; LongCollection qset = items; if (normed.size() < qset.size()) { qset = normed.keySet(); } final LongSet candidates = new LongOpenHashSet(); for (LongIterator iter = qset.iterator(); iter.hasNext();) { final long item = iter.nextLong(); LongSet users = snapshot.getItemUsers(item); if (users != null) { candidates.addAll(users); } } candidates.remove(user); logger.debug("Found {} candidate neighbors for user {}", candidates.size(), user); return new Iterable<Neighbor>() { @Override public Iterator<Neighbor> iterator() { return new NeighborIterator(user, normed, candidates); } }; }
/** * Get the IDs of the candidate neighbors for a user. * @param user The user. * @param userItems The user's rated items. * @param targetItems The set of target items. * @return The set of IDs of candidate neighbors. */ private LongSet findCandidateNeighbors(long user, LongSet userItems, LongCollection targetItems) { LongSet users = new LongOpenHashSet(100); LongIterator items; if (userItems.size() < targetItems.size()) { items = userItems.iterator(); } else { items = targetItems.iterator(); } while (items.hasNext()) { LongSet iusers = dao.query(CommonTypes.RATING) .withAttribute(CommonAttributes.ITEM_ID, items.nextLong()) .valueSet(CommonAttributes.USER_ID); if (iusers != null) { users.addAll(iusers); } } users.remove(user); return users; }
/** * Sends a world chunk to the player. This is used by world adapters in order to give the player connection * a chance to know once it is ready for spawning. * * @param chunkAdapter which should be sent to the client * @return true when the chunk has been sent, false when not */ private boolean sendWorldChunk(ChunkAdapter chunkAdapter) { this.playerChunks.add(chunkAdapter.longHashCode()); this.loadingChunks.remove(chunkAdapter.longHashCode()); this.addToSendQueue(chunkAdapter.getCachedPacket()); this.entity.getEntityVisibilityManager().updateAddedChunk(chunkAdapter); if (this.state == PlayerConnectionState.LOGIN && this.loadingChunks.isEmpty()) { int spawnXChunk = CoordinateUtils.fromBlockToChunk((int) this.entity.getLocation().getX()); int spawnZChunk = CoordinateUtils.fromBlockToChunk((int) this.entity.getLocation().getZ()); WorldAdapter worldAdapter = this.entity.getWorld(); worldAdapter.movePlayerToChunk(spawnXChunk, spawnZChunk, this.entity); this.getEntity().firstSpawn(); this.state = PlayerConnectionState.PLAYING; this.entity.getLoginPerformance().setChunkEnd(this.entity.getWorld().getServer().getCurrentTickTime()); this.entity.getLoginPerformance().print(); } return true; }