Skip to content

Commit cb74b84

Browse files
committed
add runtime_error_wrapper for flat index
1 parent 1d100af commit cb74b84

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

bindings/cpp/src/flat_index.cpp

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,27 @@ struct FlatIndexManager : public FlatIndex {
4444
~FlatIndexManager() override = default;
4545

4646
Status add(size_t n, const float* x) noexcept override {
47-
SVS_RUNTIME_TRY_BEGIN
48-
svs::data::ConstSimpleDataView<float> data{x, n, impl_->dimensions()};
49-
impl_->add(data);
50-
return Status_Ok;
51-
SVS_RUNTIME_TRY_END
47+
return runtime_error_wrapper([&] {
48+
svs::data::ConstSimpleDataView<float> data{x, n, impl_->dimensions()};
49+
impl_->add(data);
50+
});
5251
}
5352

5453
Status search(size_t n, const float* x, size_t k, float* distances, size_t* labels)
5554
const noexcept override {
56-
SVS_RUNTIME_TRY_BEGIN
57-
// TODO wrap arguments into proper data structures in FlatIndexImpl and
58-
// here
59-
impl_->search(n, x, k, distances, labels);
60-
return Status_Ok;
61-
SVS_RUNTIME_TRY_END
55+
return runtime_error_wrapper([&] {
56+
// TODO wrap arguments into proper data structures in FlatIndexImpl and
57+
// here
58+
impl_->search(n, x, k, distances, labels);
59+
});
6260
}
6361

6462
Status reset() noexcept override {
65-
SVS_RUNTIME_TRY_BEGIN
66-
impl_->reset();
67-
return Status_Ok;
68-
SVS_RUNTIME_TRY_END
63+
return runtime_error_wrapper([&] { impl_->reset(); });
6964
}
7065

7166
Status save(std::ostream& out) const noexcept override {
72-
SVS_RUNTIME_TRY_BEGIN
73-
impl_->save(out);
74-
return Status_Ok;
75-
SVS_RUNTIME_TRY_END
67+
return runtime_error_wrapper([&] { impl_->save(out); });
7668
}
7769
};
7870
} // namespace
@@ -82,27 +74,22 @@ FlatIndex::~FlatIndex() = default;
8274

8375
Status FlatIndex::build(FlatIndex** index, size_t dim, MetricType metric) noexcept {
8476
*index = nullptr;
85-
SVS_RUNTIME_TRY_BEGIN
86-
auto impl = std::make_unique<FlatIndexImpl>(dim, metric);
87-
*index = new FlatIndexManager{std::move(impl)};
88-
return Status_Ok;
89-
SVS_RUNTIME_TRY_END
77+
return runtime_error_wrapper([&] {
78+
auto impl = std::make_unique<FlatIndexImpl>(dim, metric);
79+
*index = new FlatIndexManager{std::move(impl)};
80+
});
9081
}
9182

9283
Status FlatIndex::destroy(FlatIndex* index) noexcept {
93-
SVS_RUNTIME_TRY_BEGIN
94-
delete index;
95-
return Status_Ok;
96-
SVS_RUNTIME_TRY_END
84+
return runtime_error_wrapper([&] { delete index; });
9785
}
9886

9987
Status FlatIndex::load(FlatIndex** index, std::istream& in, MetricType metric) noexcept {
10088
*index = nullptr;
101-
SVS_RUNTIME_TRY_BEGIN
102-
std::unique_ptr<FlatIndexImpl> impl{FlatIndexImpl::load(in, metric)};
103-
*index = new FlatIndexManager{std::move(impl)};
104-
return Status_Ok;
105-
SVS_RUNTIME_TRY_END
89+
return runtime_error_wrapper([&] {
90+
std::unique_ptr<FlatIndexImpl> impl{FlatIndexImpl::load(in, metric)};
91+
*index = new FlatIndexManager{std::move(impl)};
92+
});
10693
}
10794
} // namespace runtime
10895
} // namespace svs

0 commit comments

Comments
 (0)