| 1 |
/* |
| 2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 |
* |
| 4 |
* This source code is licensed under the MIT license found in the |
| 5 |
* LICENSE file in the root directory of this source tree. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "IndexReplicas_c.h" |
| 9 |
#include <faiss/IndexReplicas.h> |
| 10 |
#include "macros_impl.h" |
| 11 |
|
| 12 |
using faiss::Index; |
| 13 |
using faiss::IndexReplicas; |
| 14 |
|
| 15 |
DEFINE_DESTRUCTOR(IndexReplicas) |
| 16 |
|
| 17 |
DEFINE_GETTER(IndexReplicas, int, own_indices) |
| 18 |
DEFINE_SETTER(IndexReplicas, int, own_indices) |
| 19 |
|
| 20 |
int faiss_IndexReplicas_new(FaissIndexReplicas** p_index, idx_t d) { |
| 21 |
try { |
| 22 |
auto out = new IndexReplicas(d); |
| 23 |
*p_index = reinterpret_cast<FaissIndexReplicas*>(out); |
| 24 |
} |
| 25 |
CATCH_AND_HANDLE |
| 26 |
} |
| 27 |
|
| 28 |
int faiss_IndexReplicas_new_with_options( |
| 29 |
FaissIndexReplicas** p_index, |
| 30 |
idx_t d, |
| 31 |
int threaded) { |
| 32 |
try { |
| 33 |
auto out = new IndexReplicas(d, static_cast<bool>(threaded)); |
| 34 |
*p_index = reinterpret_cast<FaissIndexReplicas*>(out); |
| 35 |
} |
| 36 |
CATCH_AND_HANDLE |
| 37 |
} |
| 38 |
|
| 39 |
int faiss_IndexReplicas_add_replica( |
| 40 |
FaissIndexReplicas* index, |
| 41 |
FaissIndex* replica) { |
| 42 |
try { |
| 43 |
reinterpret_cast<IndexReplicas*>(index)->add_replica( |
| 44 |
reinterpret_cast<Index*>(replica)); |
| 45 |
} |
| 46 |
CATCH_AND_HANDLE |
| 47 |
} |
| 48 |
|
| 49 |
int faiss_IndexReplicas_remove_replica( |
| 50 |
FaissIndexReplicas* index, |
| 51 |
FaissIndex* replica) { |
| 52 |
try { |
| 53 |
reinterpret_cast<IndexReplicas*>(index)->remove_replica( |
| 54 |
reinterpret_cast<Index*>(replica)); |
| 55 |
} |
| 56 |
CATCH_AND_HANDLE |
| 57 |
} |
| 58 |
|
| 59 |
FaissIndex* faiss_IndexReplicas_at(FaissIndexReplicas* index, int i) { |
| 60 |
auto replica = reinterpret_cast<IndexReplicas*>(index)->at(i); |
| 61 |
return reinterpret_cast<FaissIndex*>(replica); |
| 62 |
} |