| 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 |
// -*- c -*- |
| 9 |
|
| 10 |
/// Macros and typedefs for C wrapper API declarations |
| 11 |
|
| 12 |
#ifndef FAISS_C_H |
| 13 |
#define FAISS_C_H |
| 14 |
|
| 15 |
#include <stdint.h> |
| 16 |
|
| 17 |
typedef int64_t faiss_idx_t; ///< all indices are this type |
| 18 |
typedef faiss_idx_t idx_t; |
| 19 |
typedef float faiss_component_t; ///< all vector components are this type |
| 20 |
typedef float faiss_distance_t; ///< all distances between vectors are this type |
| 21 |
|
| 22 |
/// Declare an opaque type for a class type `clazz`. |
| 23 |
#define FAISS_DECLARE_CLASS(clazz) typedef struct Faiss##clazz##_H Faiss##clazz; |
| 24 |
|
| 25 |
/// Declare an opaque type for a class type `clazz`, while |
| 26 |
/// actually aliasing it to an existing parent class type `parent`. |
| 27 |
#define FAISS_DECLARE_CLASS_INHERITED(clazz, parent) \ |
| 28 |
typedef struct Faiss##parent##_H Faiss##clazz; |
| 29 |
|
| 30 |
/// Declare a dynamic downcast operation from a base `FaissIndex*` pointer |
| 31 |
/// type to a more specific index type. The function returns the same pointer |
| 32 |
/// if the downcast is valid, and `NULL` otherwise. |
| 33 |
#define FAISS_DECLARE_INDEX_DOWNCAST(clazz) \ |
| 34 |
Faiss##clazz* faiss_##clazz##_cast(FaissIndex*); |
| 35 |
|
| 36 |
/// Declare a dynamic downcast operation from a base `FaissIndexBinary*` pointer |
| 37 |
/// type to a more specific index type. The function returns the same pointer |
| 38 |
/// if the downcast is valid, and `NULL` otherwise. |
| 39 |
#define FAISS_DECLARE_INDEX_BINARY_DOWNCAST(clazz) \ |
| 40 |
Faiss##clazz* faiss_##clazz##_cast(FaissIndexBinary*); |
| 41 |
|
| 42 |
/// Declare a dynamic downcast operation from a base `FaissSearchParameters*` |
| 43 |
/// pointer type to a more specific search parameters type. The function returns |
| 44 |
/// the same pointer if the downcast is valid, and `NULL` otherwise. |
| 45 |
#define FAISS_DECLARE_SEARCH_PARAMETERS_DOWNCAST(clazz) \ |
| 46 |
Faiss##clazz* faiss_##clazz##_cast(FaissSearchParameters*); |
| 47 |
|
| 48 |
/// Declare a getter for the field `name` in class `clazz`, |
| 49 |
/// of return type `ty` |
| 50 |
#define FAISS_DECLARE_GETTER(clazz, ty, name) \ |
| 51 |
ty faiss_##clazz##_##name(const Faiss##clazz*); |
| 52 |
|
| 53 |
/// Declare a setter for the field `name` in class `clazz`, |
| 54 |
/// in which the user provides a value of type `ty` |
| 55 |
#define FAISS_DECLARE_SETTER(clazz, ty, name) \ |
| 56 |
void faiss_##clazz##_set_##name(Faiss##clazz*, ty); |
| 57 |
|
| 58 |
/// Declare a getter and setter for the field `name` in class `clazz`. |
| 59 |
#define FAISS_DECLARE_GETTER_SETTER(clazz, ty, name) \ |
| 60 |
FAISS_DECLARE_GETTER(clazz, ty, name) \ |
| 61 |
FAISS_DECLARE_SETTER(clazz, ty, name) |
| 62 |
|
| 63 |
/// Declare a destructor function which frees an object of |
| 64 |
/// type `clazz`. |
| 65 |
#define FAISS_DECLARE_DESTRUCTOR(clazz) \ |
| 66 |
void faiss_##clazz##_free(Faiss##clazz* obj); |
| 67 |
|
| 68 |
#endif |