Skip to content

Commit fc790ae

Browse files
committed
Add: reserve_capacity_and_threads for Rust
1 parent a75bb4d commit fc790ae

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
"xstring": "cpp",
136136
"xtr1common": "cpp",
137137
"xtree": "cpp",
138-
"xutility": "cpp"
138+
"xutility": "cpp",
139+
"*.rs": "cpp"
139140
},
140141
"cSpell.words": [
141142
"allclose",

rust/lib.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ size_t NativeIndex::count(vector_key_t key) const { return index_->count(key); }
134134
bool NativeIndex::contains(vector_key_t key) const { return index_->contains(key); }
135135

136136
void NativeIndex::reserve(size_t capacity) const { index_->reserve(capacity); }
137+
void NativeIndex::reserve_capacity_and_threads(size_t capacity, size_t threads) const {
138+
index_->reserve({capacity, threads});
139+
}
137140

138141
size_t NativeIndex::dimensions() const { return index_->dimensions(); }
139142
size_t NativeIndex::connectivity() const { return index_->connectivity(); }

rust/lib.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class NativeIndex {
2525
NativeIndex(std::unique_ptr<index_dense_t> index);
2626

2727
void reserve(size_t) const;
28+
void reserve_capacity_and_threads(size_t, size_t) const;
2829

2930
void add_b1x8(vector_key_t key, rust::Slice<uint8_t const> vector) const;
3031
void add_i8(vector_key_t key, rust::Slice<int8_t const> vector) const;

rust/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ pub mod ffi {
332332

333333
pub fn new_native_index(options: &IndexOptions) -> Result<UniquePtr<NativeIndex>>;
334334
pub fn reserve(self: &NativeIndex, capacity: usize) -> Result<()>;
335+
pub fn reserve_capacity_and_threads(self: &NativeIndex, capacity: usize, threads: usize) -> Result<()>;
335336
pub fn dimensions(self: &NativeIndex) -> usize;
336337
pub fn connectivity(self: &NativeIndex) -> usize;
337338
pub fn size(self: &NativeIndex) -> usize;
@@ -1143,6 +1144,20 @@ impl Index {
11431144
self.inner.reserve(capacity)
11441145
}
11451146

1147+
/// Reserves memory for a specified number of incoming vectors & active threads.
1148+
///
1149+
/// # Arguments
1150+
///
1151+
/// * `capacity` - The desired total capacity, including the current size.
1152+
/// * `threads` - The number of threads to use for the operation.
1153+
pub fn reserve_capacity_and_threads(
1154+
self: &Index,
1155+
capacity: usize,
1156+
threads: usize,
1157+
) -> Result<(), cxx::Exception> {
1158+
self.inner.reserve_capacity_and_threads(capacity, threads)
1159+
}
1160+
11461161
/// Retrieves the number of dimensions in the vectors indexed.
11471162
pub fn dimensions(self: &Index) -> usize {
11481163
self.inner.dimensions()

0 commit comments

Comments
 (0)