Debian Codegraph @

c_api/IndexShards_c.cpp

raw
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 "IndexShards_c.h"
9 #include <faiss/IndexShards.h>
10 #include "macros_impl.h"
11
12 using faiss::Index;
13 using faiss::IndexShards;
14
15 DEFINE_DESTRUCTOR(IndexShards)
16
17 DEFINE_GETTER(IndexShards, int, own_indices)
18 DEFINE_SETTER(IndexShards, int, own_indices)
19
20 DEFINE_GETTER(IndexShards, int, successive_ids)
21 DEFINE_SETTER(IndexShards, int, successive_ids)
22
23 int faiss_IndexShards_new(FaissIndexShards** p_index, idx_t d) {
24 try {
25 auto out = new IndexShards(d);
26 *p_index = reinterpret_cast<FaissIndexShards*>(out);
27 }
28 CATCH_AND_HANDLE
29 }
30
31 int faiss_IndexShards_new_with_options(
32 FaissIndexShards** p_index,
33 idx_t d,
34 int threaded,
35 int successive_ids) {
36 try {
37 auto out = new IndexShards(
38 d,
39 static_cast<bool>(threaded),
40 static_cast<bool>(successive_ids));
41 *p_index = reinterpret_cast<FaissIndexShards*>(out);
42 }
43 CATCH_AND_HANDLE
44 }
45
46 int faiss_IndexShards_add_shard(FaissIndexShards* index, FaissIndex* shard) {
47 try {
48 reinterpret_cast<IndexShards*>(index)->add_shard(
49 reinterpret_cast<Index*>(shard));
50 }
51 CATCH_AND_HANDLE
52 }
53
54 int faiss_IndexShards_remove_shard(FaissIndexShards* index, FaissIndex* shard) {
55 try {
56 reinterpret_cast<IndexShards*>(index)->remove_shard(
57 reinterpret_cast<Index*>(shard));
58 }
59 CATCH_AND_HANDLE
60 }
61
62 FaissIndex* faiss_IndexShards_at(FaissIndexShards* index, int i) {
63 auto shard = reinterpret_cast<IndexShards*>(index)->at(i);
64 return reinterpret_cast<FaissIndex*>(shard);
65 }