/** * The keys closest to the key. * Returned list will never contain us. * @return non-null, closest first */ public List<T> getClosest(T key, int max) { return getClosest(key, max, Collections.<T> emptySet()); }
/** * The keys closest to us. * Returned list will never contain us. * @return non-null, closest first */ public List<T> getClosest(int max) { return getClosest(max, Collections.<T> emptySet()); }
/** * DHT * @param h either a InfoHash or a NID */ public List<NodeInfo> findClosest(SHA1Hash h, int numWant) { NID key; if (h instanceof NID) key = (NID) h; else key = new NID(h.getData()); List<NID> keys = _kad.getClosest(key, numWant); List<NodeInfo> rv = new ArrayList<NodeInfo>(keys.size()); for (NID nid : keys) { NodeInfo ninfo = _nodeMap.get(nid); if (ninfo != null) rv.add(ninfo); } return rv; }
return getClosest(max, toIgnore); List<T> rv = new ArrayList<T>(max); int count = 0;
/** @since 0.9.10 */ public void testClosest() { byte val[] = new byte[Hash.HASH_LENGTH]; for (int i = 0; i < 23; i++) { context.random().nextBytes(val); Hash h = new Hash(val); List<Hash> c = set.getClosest(h, i); assertTrue(c.size() == i); } } }