public String findKey(byte[] obj) { if (nodeKeySlots.size() == 0) { return null; } long objHash = hashFn.hashBytes(obj).asLong(); Long2ObjectSortedMap<String> subMap = nodeKeySlots.tailMap(objHash); if (subMap.isEmpty()) { return nodeKeySlots.long2ObjectEntrySet().first().getValue(); } Long2ObjectMap.Entry<String> firstEntry = subMap.long2ObjectEntrySet().first(); return firstEntry.getValue(); }
/** * Returns true if we have fewer or equal strings to the number of buckets. * @param buckets Number of buckets we want. */ public boolean allStringsKnown(int buckets) { if (this.min == null) // no non-null values return true; return this.data.size() <= buckets; }
public int size() { return this.data.size(); }
@Nullable public MinKSet<RowSnapshot> add(@Nullable MinKSet<RowSnapshot>left, @Nullable MinKSet<RowSnapshot> right) { assert left != null; assert right != null; Comparator<RowSnapshot> comp = left.comp; RowSnapshot minRS, maxRS; long present = left.presentCount + right.presentCount; if (left.presentCount == 0) { minRS = right.min; maxRS = right.max; } else if (right.presentCount == 0) { minRS = right.min; maxRS = right.max; } else { minRS = comp.compare(left.min, right.min) < 0 ? left.min : right.min; maxRS = comp.compare(left.max, right.max) > 0 ? left.max : right.max; } Long2ObjectRBTreeMap<RowSnapshot> data = new Long2ObjectRBTreeMap<>(); data.putAll(left.data); data.putAll(right.data); while (data.size() > this.numSamples) { long maxKey = data.lastLongKey(); data.remove(maxKey); } return new MinKSet<RowSnapshot>(this.numSamples, data, comp, minRS, maxRS, present, 0); } }
data.putAll(left.data); data.putAll(right.data); while (data.size() > this.maxSize) { long maxKey = data.lastLongKey(); data.remove(maxKey);
public String findKey(byte[] obj) { if (nodeKeySlots.size() == 0) { return null; } long objHash = hashFn.hashBytes(obj).asLong(); Long2ObjectSortedMap<String> subMap = nodeKeySlots.tailMap(objHash); if (subMap.isEmpty()) { return nodeKeySlots.long2ObjectEntrySet().first().getValue(); } Long2ObjectMap.Entry<String> firstEntry = subMap.long2ObjectEntrySet().first(); return firstEntry.getValue(); }
public String findKey(byte[] obj) { if (nodeKeySlots.size() == 0) { return null; } long objHash = hashFn.hashBytes(obj).asLong(); Long2ObjectSortedMap<String> subMap = nodeKeySlots.tailMap(objHash); if (subMap.isEmpty()) { return nodeKeySlots.long2ObjectEntrySet().first().getValue(); } Long2ObjectMap.Entry<String> firstEntry = subMap.long2ObjectEntrySet().first(); return firstEntry.getValue(); }