Skip to content

Commit 0017908

Browse files
author
Jonathan Ellis
committed
moving updateAndGet last is not correct
1 parent 9143fd3 commit 0017908

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

jvector-base/src/main/java/io/github/jbellis/jvector/quantization/MutablePQVectors.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ public MutablePQVectors(ProductQuantization pq) {
4848
@Override
4949
public void encodeAndSet(int ordinal, VectorFloat<?> vector) {
5050
ensureChunkCapacity(ordinal);
51-
pq.encodeTo(vector, get(ordinal));
51+
// increase count first so get() works
5252
vectorCount.updateAndGet(current -> max(current, ordinal + 1));
53+
pq.encodeTo(vector, get(ordinal));
5354
}
5455

5556
@Override
5657
public void setZero(int ordinal) {
5758
ensureChunkCapacity(ordinal);
58-
get(ordinal).zero();
59+
// increase count first so get() works
5960
vectorCount.updateAndGet(current -> max(current, ordinal + 1));
61+
get(ordinal).zero();
6062
}
6163

6264
private void ensureChunkCapacity(int ordinal) {

0 commit comments

Comments
 (0)