/** * If {@code x(v)} or {@code y(v)} returns {@code NaN}, this method returns immediately without * adding {@code v} to the tree. */ public void add(int v) { float x = x(v); if (Float.isNaN(x)) return; float y = y(v); if (Float.isNaN(y)) return; LeafNode<Bucket> leaf = leaf(x, y); Bucket bucket = leaf.bucket; // The default return value for bucket.dupes is set to bucket.singles, // so iff bucket.dupes does not contain xyKey, we will end up appending // to bucket.singles -- which is exactly what we want. // // This is confusing to read, but it avoids double-checking the "contains // key?" condition. The map is already doing the check for us -- not worth // doing the same check again. // long xyKey = xyToKey(x, y); bucket.dupes.get(xyKey).append(v); if (bucketSize(bucket) > maxBucketSize) { compactBucket(bucket); if (bucketSize(bucket) > 0.9 * maxBucketSize) splitLeaf(leaf); } }