Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
AuxIndexStructures_c.h
1 /**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD+Patents license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 // Copyright 2004-present Facebook. All Rights Reserved.
10 // -*- c -*-
11
12 #ifndef FAISS_AUX_INDEX_STRUCTURES_C_H
13 #define FAISS_AUX_INDEX_STRUCTURES_C_H
14
15 #include "Index_c.h"
16 #include "faiss_c.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 FAISS_DECLARE_CLASS(RangeSearchResult)
23
24 FAISS_DECLARE_GETTER(RangeSearchResult, size_t, nq)
25
26 int faiss_RangeSearchResult_new(FaissRangeSearchResult** p_rsr, idx_t nq);
27
28 int faiss_RangeSearchResult_new_with(FaissRangeSearchResult** p_rsr, idx_t nq, int alloc_lims);
29
30 /// called when lims contains the nb of elements result entries
31 /// for each query
32 int faiss_RangeSearchResult_do_allocation(FaissRangeSearchResult* rsr);
33
34 FAISS_DECLARE_DESTRUCTOR(RangeSearchResult)
35
36 /// getter for buffer_size
37 FAISS_DECLARE_GETTER(RangeSearchResult, size_t, buffer_size)
38
39 /// getter for lims: size (nq + 1)
40 void faiss_RangeSearchResult_lims(
41 FaissRangeSearchResult* rsr, size_t** lims);
42
43 /// getter for labels and respective distances (not sorted):
44 /// result for query i is labels[lims[i]:lims[i+1]]
45 void faiss_RangeSearchResult_labels(
46 FaissRangeSearchResult* rsr, idx_t** labels, float** distances);
47
48
49 /** Encapsulates a set of ids to remove. */
50 FAISS_DECLARE_CLASS(IDSelector)
51 FAISS_DECLARE_DESTRUCTOR(IDSelector)
52
53 int faiss_IDSelector_is_member(const FaissIDSelector* sel, idx_t id);
54
55 /** remove ids between [imni, imax) */
56 FAISS_DECLARE_CLASS(IDSelectorRange)
57 FAISS_DECLARE_DESTRUCTOR(IDSelectorRange)
58
59 FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imin)
60 FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imax)
61
62 int faiss_IDSelectorRange_new(FaissIDSelectorRange** p_sel, idx_t imin, idx_t imax);
63
64 /** Remove ids from a set. Repetitions of ids in the indices set
65 * passed to the constructor does not hurt performance. The hash
66 * function used for the bloom filter and GCC's implementation of
67 * unordered_set are just the least significant bits of the id. This
68 * works fine for random ids or ids in sequences but will produce many
69 * hash collisions if lsb's are always the same */
70 FAISS_DECLARE_CLASS(IDSelectorBatch)
71
72 FAISS_DECLARE_GETTER(IDSelectorBatch, int, nbits)
73 FAISS_DECLARE_GETTER(IDSelectorBatch, idx_t, mask)
74
75 int faiss_IDSelectorBatch_new(FaissIDSelectorBatch** p_sel, long n, const idx_t* indices);
76
77 // Below are structures used only by Index implementations
78
79 /** List of temporary buffers used to store results before they are
80 * copied to the RangeSearchResult object. */
81 FAISS_DECLARE_CLASS(BufferList)
82 FAISS_DECLARE_DESTRUCTOR(BufferList)
83
84 FAISS_DECLARE_GETTER(BufferList, size_t, buffer_size)
85 FAISS_DECLARE_GETTER(BufferList, size_t, wp)
86
87 typedef struct FaissBuffer {
88 idx_t *ids;
89 float *dis;
90 } FaissBuffer;
91
92 int faiss_BufferList_append_buffer(FaissBufferList* bl);
93
94 int faiss_BufferList_new(FaissBufferList** p_bl, size_t buffer_size);
95
96 int faiss_BufferList_add(FaissBufferList* bl, idx_t id, float dis);
97
98 /// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
99 /// tables dest_ids, dest_dis
100 int faiss_BufferList_copy_range(
101 FaissBufferList* bl, size_t ofs, size_t n, idx_t *dest_ids, float *dest_dis);
102
103 /// the entries in the buffers are split per query
104 FAISS_DECLARE_CLASS(RangeSearchPartialResult)
105
106 FAISS_DECLARE_GETTER(RangeSearchPartialResult, FaissRangeSearchResult*, res)
107
108 int faiss_RangeSearchPartialResult_new(
109 FaissRangeSearchPartialResult** p_res, FaissRangeSearchResult* res_in);
110
111 int faiss_RangeSearchPartialResult_finalize(
112 FaissRangeSearchPartialResult* res);
113
114 /// called by range_search before do_allocation
115 int faiss_RangeSearchPartialResult_set_lims(
116 FaissRangeSearchPartialResult* res);
117
118 /// called by range_search after do_allocation
119 int faiss_RangeSearchPartialResult_set_result(
120 FaissRangeSearchPartialResult* res, int incremental);
121
122 /// result structure for a single query
123 FAISS_DECLARE_CLASS(QueryResult)
124 FAISS_DECLARE_GETTER(QueryResult, idx_t, qno)
125 FAISS_DECLARE_GETTER(QueryResult, size_t, nres)
126 FAISS_DECLARE_GETTER(QueryResult, FaissRangeSearchPartialResult*, pres)
127
128 int faiss_RangeSearchPartialResult_new_result(
129 FaissRangeSearchPartialResult* res, idx_t qno, FaissQueryResult** qr);
130
131 int faiss_QueryResult_add(FaissQueryResult* qr, float dis, idx_t id);
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif
FaissBuffer
Definition: AuxIndexStructures_c.h:87