@Override public int size() { synchronized (sync) { return collection.size(); } } @Override
@Override public int size() { return collection.size(); } @Override
@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; }
/** * Creates a new hash big set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new hash big set. * @param f * the load factor. */ public LongOpenHashBigSet(final LongCollection c, final float f) { this(c.size(), f); addAll(c); } /**
/** * Creates a new hash set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new hash set. * @param f * the load factor. */ public LongOpenHashSet(final LongCollection c, final float f) { this(c.size(), f); addAll(c); } /**
/** * Creates a new array set copying the contents of a given collection. * * @param c * a collection. */ public LongArraySet(LongCollection c) { this(c.size()); addAll(c); } /**
/** * Creates a new hash set copying a given type-specific collection. * * @param c * a type-specific collection to be copied into the new hash set. * @param f * the load factor. */ public LongLinkedOpenHashSet(final LongCollection c, final float f) { this(c.size(), f); addAll(c); } /**
@Test public void testGetItemIds() { LongCollection items = snap.getItemIds(); assertEquals(5, items.size()); assertTrue(items.contains(7)); assertTrue(items.contains(8)); assertTrue(items.contains(9)); assertTrue(items.contains(10)); assertTrue(items.contains(11)); }
@Override public boolean addAll(LongCollection c) { if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
@Override public boolean addAll(LongCollection c) { if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
/** * Creates a new array list and fills it with a given type-specific collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public LongArrayList(final LongCollection c) { this(c.size()); size = LongIterators.unwrap(c.iterator(), a); } /**
@Override public boolean addAll(LongCollection c) { if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
@Override public boolean addAll(LongCollection c) { if (f <= .5) ensureCapacity(c.size()); // The resulting collection will be sized for c.size() elements else tryCapacity(size() + c.size()); // The resulting collection will be tentatively sized for size() + c.size() // elements return super.addAll(c); } @Override
public boolean containsAll(LongCollection c) { final LongIterator i = c.iterator(); int n = c.size(); while (n-- != 0) if (!contains(i.nextLong())) return false; return true; }
public boolean containsAll(LongCollection c) { final LongIterator i = c.iterator(); int n = c.size(); while (n-- != 0) if (!contains(i.nextLong())) return false; return true; }
public boolean containsAll(LongCollection c) { final LongIterator i = c.iterator(); int n = c.size(); while (n-- != 0) if (!contains(i.nextLong())) return false; return true; }
@Override public boolean addAll(LongCollection c) { final long size = c instanceof Size64 ? ((Size64) c).size64() : c.size(); if (f <= .5) ensureCapacity(size); // The resulting collection will be size for c.size() elements else ensureCapacity(size64() + size); // The resulting collection will be sized for size() + c.size() elements return super.addAll(c); } @Override