mikemccand commented on code in PR #15979: URL: https://github.com/apache/lucene/pull/15979#discussion_r3690999210
########## lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/dedup/DedupGroup.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.codecs.lucene106.dedup; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.lucene.internal.hppc.LongIntHashMap; +import org.apache.lucene.internal.hppc.ObjectCursor; +import org.apache.lucene.util.Accountable; + +/** + * Interns vectors so that each distinct value is stored once. {@link #addUnique} returns the group + * ordinal for a vector, adding it (via {@link #copy}) only if not already present. Callers with the + * same {@code (dimension, encoding)} share a group, so an identical vector across fields is stored + * a single time. + * + * <p>Not thread-safe; a group is confined to the writer that created it. + * + * @lucene.experimental + */ +abstract sealed class DedupGroup<T> implements Accountable + permits DedupFlushContext.ByteGroup, + DedupFlushContext.FloatGroup, + DedupFlushContext.Float16Group, + DedupMergeContext.DedupMergeGroup { + + /** + * Map for vector hash -> group ord. Only a hint and not the ground truth due to possibility of + * hash collisions, where a full equality check must be performed. Review Comment: Cool, I hadn't realized the birthday paradox applies to hash tables, but it clearly does! Only 23 people in a [365.2422 sized hash table](https://en.wikipedia.org/wiki/Year#:~:text=%5B5%5D-,Revised%20Julian%20calendar,-The%20Revised%20Julian) and you have a 50% chance of a "collision" (two people with same birthday). So that is the best-case for hash functions (when there is truly no correlation b/w hash function and input vectors, so the hash locations are effectively random-like). And yet we size our hash table arrays for X (75? 50?) % occupancy before growing, far higher than 23 / 365.2422 = ~6.297% occupancy. But that's OK, the 23 people figure just means when you did those 23 inserts, did any of them hit a false collision (and need linear probing). Seen more positively, there is a 50% chance that those 23 inserts had no conflict... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
