in java/com_spotify_voyager_jni_Index.cpp [374:395]
jlongArray Java_com_spotify_voyager_jni_Index_addItems___3_3FI(
JNIEnv *env, jobject self, jobjectArray vectors, jint numThreads) {
try {
std::shared_ptr<Index> index = getHandle<Index>(env, self);
std::vector<hnswlib::labeltype> nativeIds =
index->addItems(toNDArray(env, vectors), {}, numThreads);
// Allocate a Java long array for the IDs:
static_assert(
sizeof(hnswlib::labeltype) == sizeof(jlong),
"addItems expects hnswlib::labeltype to be a 64-bit integer.");
jlongArray javaIds = env->NewLongArray(nativeIds.size());
env->SetLongArrayRegion(javaIds, 0, nativeIds.size(),
(jlong *)nativeIds.data());
return javaIds;
} catch (std::exception const &e) {
if (!env->ExceptionCheck()) {
env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
}
}
return nullptr;
}