in java/com_spotify_voyager_jni_Index.cpp [397:419]
jlongArray Java_com_spotify_voyager_jni_Index_addItems___3_3F_3JI(
JNIEnv *env, jobject self, jobjectArray vectors, jlongArray ids,
jint numThreads) {
try {
std::shared_ptr<Index> index = getHandle<Index>(env, self);
std::vector<hnswlib::labeltype> nativeIds = index->addItems(
toNDArray(env, vectors), toUnsignedStdVector(env, ids), 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;
}