Fix: Deserialize

This commit is contained in:
Davit Vardanyan 2023-08-28 16:18:12 +04:00
parent a2686af496
commit 9190fb2ba3
2 changed files with 11 additions and 12 deletions

2
contrib/usearch vendored

@ -1 +1 @@
Subproject commit 387b78b28b17b8954024ffc81e97cbcfa10d1f30
Subproject commit c6329e9bfb893a92c28d825cc7982580f65bbfae

View File

@ -35,7 +35,7 @@ USearchIndexWithSerialization<Metric>::USearchIndexWithSerialization(size_t dime
}
template <unum::usearch::metric_kind_t Metric>
void USearchIndexWithSerialization<Metric>::serialize([[maybe_unused]] WriteBuffer & ostr) const
void USearchIndexWithSerialization<Metric>::serialize(WriteBuffer & ostr) const
{
auto callback = [&ostr](void * from, size_t n)
{
@ -43,21 +43,20 @@ void USearchIndexWithSerialization<Metric>::serialize([[maybe_unused]] WriteBuff
return true;
};
Base::stream(callback);
Base::save_to_stream(callback);
}
template <unum::usearch::metric_kind_t Metric>
void USearchIndexWithSerialization<Metric>::deserialize([[maybe_unused]] ReadBuffer & istr)
void USearchIndexWithSerialization<Metric>::deserialize(ReadBuffer & istr)
{
BufferBase::Position & pos = istr.position();
unum::usearch::memory_mapped_file_t memory_map(pos, istr.buffer().size() - istr.count());
Base::view(std::move(memory_map));
pos += Base::stream_length();
auto callback = [&istr](void * from, size_t n)
{
istr.readStrict(reinterpret_cast<char *>(from), n);
return true;
};
Base::load_from_stream(callback);
auto copy = Base::copy();
if (!copy)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Could not copy usearch index");
Base::swap(copy.index);
}
template <unum::usearch::metric_kind_t Metric>