Skip to content
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

markDeleted/unmarkDeleted #35

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions java/com_spotify_voyager_jni_Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,29 @@ jint Java_com_spotify_voyager_jni_Index_getEf(JNIEnv *env, jobject self) {
return 0;
}

// TODO: Add markDeleted
void Java_com_spotify_voyager_jni_Index_markDeleted(JNIEnv *env, jobject self,
jlong label) {
try {
Index *index = getHandle<Index>(env, self);
index->markDeleted(label);
} catch (std::exception const &e) {
if (!env->ExceptionCheck()) {
env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
}
}
}

// TODO: Add unmarkDeleted
void Java_com_spotify_voyager_jni_Index_unmarkDeleted(JNIEnv *env, jobject self,
jlong label) {
try {
Index *index = getHandle<Index>(env, self);
index->unmarkDeleted(label);
} catch (std::exception const &e) {
if (!env->ExceptionCheck()) {
env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
}
}
}

// TODO: Add resizeIndex

Expand Down
12 changes: 12 additions & 0 deletions java/src/test/java/com/spotify/voyager/jni/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.spotify.voyager.jni.Index.StorageDataType;
Expand Down Expand Up @@ -239,6 +240,17 @@ private void runTestWith(
}
}
}
// Test markDeleted and unmarkDeleted
index.markDeleted(0);

// Try getting the vector out - we should not get it
assertThrows(RuntimeException.class, () -> index.getVector(0));

// Now let's unmark it
index.unmarkDeleted(0);

// And the resulting call should pass:
assertNotNull(index.getVector(0));
}
}
}
Loading