/** * No lock required. * FIXME will split the closest buckets too far if B > 1 and K < 2**B * Won't ever really happen and if it does it still works. */ private boolean shouldSplit(KBucket<T> b) { return b.getRangeBegin() != b.getRangeEnd() && b.getKeyCount() > BUCKET_SIZE; }
/** * The current number of entries. */ public int size() { int rv = 0; getReadLock(); try { for (KBucket<T> b : _buckets) { rv += b.getKeyCount(); } } finally { releaseReadLock(); } return rv; }
/** * For every bucket that hasn't been updated in this long, * or isn't close to full, * generate a random key that would be a member of that bucket. * The returned keys may be searched for to "refresh" the buckets. * @return non-null, closest first */ public List<T> getExploreKeys(long age) { List<T> rv = new ArrayList<T>(_buckets.size()); long old = _context.clock().now() - age; getReadLock(); try { for (KBucket<T> b : _buckets) { int curSize = b.getKeyCount(); // Always explore the closest bucket if ((b.getRangeBegin() == 0) || (b.getLastChanged() < old || curSize < BUCKET_SIZE * 3 / 4)) rv.add(generateRandomKey(b)); } } finally { releaseReadLock(); } return rv; }
if (b2.getKeyCount() > BUCKET_SIZE) {