-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make BitSet no longer implement Bits. #14996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,7 +214,9 @@ private TopDocs getLeafResults( | |
|
|
||
| // Perform the approximate kNN search | ||
| // We pass cost + 1 here to account for the edge case when we explore exactly cost vectors | ||
| TopDocs results = approximateSearch(ctx, acceptDocs, cost + 1, timeLimitingKnnCollectorManager); | ||
| TopDocs results = | ||
| approximateSearch( | ||
| ctx, acceptDocs.asReadOnlyBits(), cost + 1, timeLimitingKnnCollectorManager); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Within the HNSW format, we do this: We determine the filter size via casting the Or |
||
|
|
||
| if ((results.totalHits.relation() == TotalHits.Relation.EQUAL_TO | ||
| // We know that there are more than `perLeafTopK` available docs, if we didn't even get | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| */ | ||
| package org.apache.lucene.util; | ||
|
|
||
| import org.apache.lucene.search.DocIdSetIterator; | ||
|
|
||
| /** Immutable twin of FixedBitSet. */ | ||
| final class FixedBits implements Bits { | ||
|
|
||
|
|
@@ -31,8 +33,17 @@ public boolean get(int index) { | |
| } | ||
|
|
||
| @Override | ||
| public void applyMask(FixedBitSet dest, int offset) { | ||
| bitSet.applyMask(dest, offset); | ||
| public void applyMask(FixedBitSet bitSet, int offset) { | ||
| // Note: Some scorers don't track maxDoc and may thus call this method with an offset that is | ||
| // beyond bitSet.length() | ||
| int length = Math.min(bitSet.length(), length() - offset); | ||
| if (length >= 0) { | ||
| FixedBitSet.andRange(this.bitSet, offset, bitSet, 0, length); | ||
| } | ||
| if (length < bitSet.length() | ||
| && bitSet.nextSetBit(Math.max(0, length)) != DocIdSetIterator.NO_MORE_DOCS) { | ||
| throw new IllegalArgumentException("Some bits are set beyond the end of live docs"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment refers to "live docs" but the method is generic and could apply to other kinds of bit set applications - maybe change to "beyond the end of the bit set"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'll fix. |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * 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.util; | ||
|
|
||
| /** Unmodifiable {@link Bits} view on a {@link SparseFixedBitSet}. */ | ||
| final class SparseFixedBits implements Bits { | ||
|
|
||
| final SparseFixedBitSet bitSet; | ||
|
|
||
| SparseFixedBits(SparseFixedBitSet bitSet) { | ||
| this.bitSet = bitSet; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean get(int index) { | ||
| return bitSet.get(index); | ||
| } | ||
|
|
||
| @Override | ||
| public int length() { | ||
| return bitSet.length(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why we are changing these signatures - it seems the call sites still always use FixedBitSet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Bitsare indeed always created biaFixedBitSet#asReadOnlyBitsbut I liked doing it on the call site better than in this constructor. Since it's a private constructor, it doesn't break users.