<divclass="line"><aname="l00002"></a><spanclass="lineno"> 2</span> <spanclass="comment"> * Copyright (c) Facebook, Inc. and its affiliates.</span></div>
<divclass="line"><aname="l00004"></a><spanclass="lineno"> 4</span> <spanclass="comment"> * This source code is licensed under the MIT license found in the</span></div>
<divclass="line"><aname="l00005"></a><spanclass="lineno"> 5</span> <spanclass="comment"> * LICENSE file in the root directory of this source tree.</span></div>
<divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> <spanclass="comment">// Auxiliary index structures, that are used in indexes but that can</span></div>
<divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span> <spanclass="comment">// be forward-declared</span></div>
<divclass="line"><aname="l00027"></a><spanclass="lineno"> 27</span> <spanclass="comment">/** The objective is to have a simple result structure while</span></div>
<divclass="line"><aname="l00028"></a><spanclass="lineno"> 28</span> <spanclass="comment"> * minimizing the number of mem copies in the result. The method</span></div>
<divclass="line"><aname="l00029"></a><spanclass="lineno"> 29</span> <spanclass="comment"> * do_allocation can be overloaded to allocate the result tables in</span></div>
<divclass="line"><aname="l00030"></a><spanclass="lineno"> 30</span> <spanclass="comment"> * the matrix type of a scripting language like Lua or Python. */</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1RangeSearchResult.html#a29269b98c33af874d379ca4f62408b90"> 32</a></span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1RangeSearchResult.html#a29269b98c33af874d379ca4f62408b90">nq</a>; <spanclass="comment">///< nb of queries</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1RangeSearchResult.html#aa8ff848474a4cc16c5464cc4ec187824"> 37</a></span>  idx_t *<aclass="code"href="structfaiss_1_1RangeSearchResult.html#aa8ff848474a4cc16c5464cc4ec187824">labels</a>; <spanclass="comment">///< result for query i is labels[lims[i]:lims[i+1]]</span></div>
<divclass="line"><aname="l00040"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1RangeSearchResult.html#a39342ad2e9ad8b90f6e95dafd3287f49"> 40</a></span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1RangeSearchResult.html#a39342ad2e9ad8b90f6e95dafd3287f49">buffer_size</a>; <spanclass="comment">///< size of the result buffers used</span></div>
<divclass="line"><aname="l00042"></a><spanclass="lineno"> 42</span> <spanclass="comment"> /// lims must be allocated on input to range_search.</span></div>
<divclass="line"><aname="l00045"></a><spanclass="lineno"> 45</span> <spanclass="comment"> /// called when lims contains the nb of elements result entries</span></div>
<divclass="line"><aname="l00046"></a><spanclass="lineno"> 46</span> <spanclass="comment"> /// for each query</span></div>
<divclass="line"><aname="l00072"></a><spanclass="lineno"> 72</span> <spanclass="comment">/** Remove ids from a set. Repetitions of ids in the indices set</span></div>
<divclass="line"><aname="l00073"></a><spanclass="lineno"> 73</span> <spanclass="comment"> * passed to the constructor does not hurt performance. The hash</span></div>
<divclass="line"><aname="l00074"></a><spanclass="lineno"> 74</span> <spanclass="comment"> * function used for the bloom filter and GCC's implementation of</span></div>
<divclass="line"><aname="l00075"></a><spanclass="lineno"> 75</span> <spanclass="comment"> * unordered_set are just the least significant bits of the id. This</span></div>
<divclass="line"><aname="l00076"></a><spanclass="lineno"> 76</span> <spanclass="comment"> * works fine for random ids or ids in sequences but will produce many</span></div>
<divclass="line"><aname="l00077"></a><spanclass="lineno"> 77</span> <spanclass="comment"> * hash collisions if lsb's are always the same */</span></div>
<divclass="line"><aname="l00083"></a><spanclass="lineno"> 83</span>  std::vector<uint8_t> bloom; <spanclass="comment">// assumes low bits of id are a good hash value</span></div>
<divclass="line"><aname="l00095"></a><spanclass="lineno"> 95</span> <spanclass="comment"> * The main constraint here is that we want to support parallel</span></div>
<divclass="line"><aname="l00096"></a><spanclass="lineno"> 96</span> <spanclass="comment"> * queries from different threads in various ways: 1 thread per query,</span></div>
<divclass="line"><aname="l00097"></a><spanclass="lineno"> 97</span> <spanclass="comment"> * several threads per query. We store the actual results in blocks of</span></div>
<divclass="line"><aname="l00098"></a><spanclass="lineno"> 98</span> <spanclass="comment"> * fixed size rather than exponentially increasing memory. At the end,</span></div>
<divclass="line"><aname="l00099"></a><spanclass="lineno"> 99</span> <spanclass="comment"> * we copy the block content to a linear result array.</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment">/** List of temporary buffers used to store results before they are</span></div>
<divclass="line"><aname="l00103"></a><spanclass="lineno"> 103</span> <spanclass="comment"> * copied to the RangeSearchResult object. */</span></div>
<divclass="line"><aname="l00116"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1BufferList.html#af4d7ddcd77f328a12a7da89d8febe5d9"> 116</a></span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1BufferList.html#af4d7ddcd77f328a12a7da89d8febe5d9">wp</a>; <spanclass="comment">///< write pointer in the last buffer.</span></div>
<divclass="line"><aname="l00125"></a><spanclass="lineno"> 125</span> <spanclass="comment"> /// add one result, possibly appending a new buffer if needed</span></div>
<divclass="line"><aname="l00128"></a><spanclass="lineno"> 128</span> <spanclass="comment"> /// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to</span></div>
<divclass="line"><aname="l00140"></a><spanclass="lineno"> 140</span>  idx_t qno; <spanclass="comment">//< id of the query</span></div>
<divclass="line"><aname="l00141"></a><spanclass="lineno"> 141</span> <spanclass="keywordtype">size_t</span> nres; <spanclass="comment">//< nb of results for this query</span></div>
<divclass="line"><aname="l00144"></a><spanclass="lineno"> 144</span> <spanclass="comment"> /// called by search function to report a new result</span></div>
<divclass="line"><aname="l00148"></a><spanclass="lineno"> 148</span> <spanclass="comment">/// the entries in the buffers are split per query</span></div>
<divclass="line"><aname="l00152"></a><spanclass="lineno"> 152</span> <spanclass="comment"> /// eventually the result will be stored in res_in</span></div>
<divclass="line"><aname="l00162"></a><spanclass="lineno"> 162</span> <spanclass="comment"> * functions used at the end of the search to merge the result</span></div>
<divclass="line"><aname="l00166"></a><spanclass="lineno"> 166</span> <spanclass="comment"> /// called by range_search before do_allocation</span></div>
<divclass="line"><aname="l00169"></a><spanclass="lineno"> 169</span> <spanclass="comment"> /// called by range_search after do_allocation</span></div>
<divclass="line"><aname="l00172"></a><spanclass="lineno"> 172</span> <spanclass="comment"> /// merge a set of PartialResult's into one RangeSearchResult</span></div>
<divclass="line"><aname="l00173"></a><spanclass="lineno"> 173</span> <spanclass="comment"> /// on ouptut the partialresults are empty!</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment">// return a file number that can be memory-mapped</span></div>
<divclass="line"><aname="l00205"></a><spanclass="lineno"> 205</span> <spanclass="comment">// return a file number that can be memory-mapped</span></div>
<divclass="line"><aname="l00224"></a><spanclass="lineno"> 224</span> <spanclass="comment"> * The distance computer maintains a current query and computes</span></div>
<divclass="line"><aname="l00225"></a><spanclass="lineno"> 225</span> <spanclass="comment"> * distances to elements in an index that supports random access.</span></div>
<divclass="line"><aname="l00227"></a><spanclass="lineno"> 227</span> <spanclass="comment"> * The DistanceComputer is not intended to be thread-safe (eg. because</span></div>
<divclass="line"><aname="l00228"></a><spanclass="lineno"> 228</span> <spanclass="comment"> * it maintains counters) so the distance functions are not const,</span></div>
<divclass="line"><aname="l00229"></a><spanclass="lineno"> 229</span> <spanclass="comment"> * instanciate one from each thread if needed.</span></div>
<divclass="line"><aname="l00237"></a><spanclass="lineno"> 237</span> <spanclass="comment"> /// compute distance of vector i to current query</span></div>
<divclass="line"><aname="l00240"></a><spanclass="lineno"> 240</span> <spanclass="comment"> /// compute distance between two stored vectors</span></div>
<divclass="line"><aname="l00241"></a><spanclass="lineno"> 241</span> <spanclass="comment"></span><spanclass="keyword">virtual</span><spanclass="keywordtype">float</span><aclass="code"href="structfaiss_1_1DistanceComputer.html#a4b7236a757c788401aac00598ed902c7">symmetric_dis</a> (idx_t i, idx_t j) = 0;</div>
<divclass="line"><aname="l00257"></a><spanclass="lineno"> 257</span> <spanclass="comment"> * - an interrupt callback is set</span></div>
<divclass="line"><aname="l00258"></a><spanclass="lineno"> 258</span> <spanclass="comment"> * - the callback retuns true</span></div>
<divclass="line"><aname="l00259"></a><spanclass="lineno"> 259</span> <spanclass="comment"> * if this is the case, then throw an exception</span></div>
<divclass="line"><aname="l00263"></a><spanclass="lineno"> 263</span> <spanclass="comment"> /// same as check() but return true if is interrupted instead of</span></div>
<divclass="line"><aname="l00267"></a><spanclass="lineno"> 267</span> <spanclass="comment"> /** assuming each iteration takes a certain number of flops, what</span></div>
<divclass="line"><aname="l00268"></a><spanclass="lineno"> 268</span> <spanclass="comment"> * is a reasonable interval to check for interrupts?</span></div>
<divclass="ttc"id="structfaiss_1_1DistanceComputer_html_a4b7236a757c788401aac00598ed902c7"><divclass="ttname"><ahref="structfaiss_1_1DistanceComputer.html#a4b7236a757c788401aac00598ed902c7">faiss::DistanceComputer::symmetric_dis</a></div><divclass="ttdeci">virtual float symmetric_dis(idx_t i, idx_t j)=0</div><divclass="ttdoc">compute distance between two stored vectors </div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html_abd6ae2a92bc18b6528aadf39370d041c"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html#abd6ae2a92bc18b6528aadf39370d041c">faiss::RangeSearchPartialResult::queries</a></div><divclass="ttdeci">std::vector< RangeQueryResult > queries</div><divclass="ttdoc">query ids + nb of results per query. </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00156">AuxIndexStructures.h:156</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchResult_html_a29269b98c33af874d379ca4f62408b90"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchResult.html#a29269b98c33af874d379ca4f62408b90">faiss::RangeSearchResult::nq</a></div><divclass="ttdeci">size_t nq</div><divclass="ttdoc">nb of queries </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00032">AuxIndexStructures.h:32</a></div></div>
<divclass="ttc"id="structfaiss_1_1DistanceComputer_html_aaa4472453365b786adc2ab21e9cee5ec"><divclass="ttname"><ahref="structfaiss_1_1DistanceComputer.html#aaa4472453365b786adc2ab21e9cee5ec">faiss::DistanceComputer::set_query</a></div><divclass="ttdeci">virtual void set_query(const float *x)=0</div><divclass="ttdoc">called before computing distances </div></div>
<divclass="ttc"id="structfaiss_1_1RangeQueryResult_html"><divclass="ttname"><ahref="structfaiss_1_1RangeQueryResult.html">faiss::RangeQueryResult</a></div><divclass="ttdoc">result structure for a single query </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00138">AuxIndexStructures.h:138</a></div></div>
<divclass="ttc"id="structfaiss_1_1BufferList_html_aa124ff3a7e6a98960e12a8b32bdaec42"><divclass="ttname"><ahref="structfaiss_1_1BufferList.html#aa124ff3a7e6a98960e12a8b32bdaec42">faiss::BufferList::append_buffer</a></div><divclass="ttdeci">void append_buffer()</div><divclass="ttdoc">create a new buffer </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00090">AuxIndexStructures.cpp:90</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html_ab6a385008493c7b630e4e7bc56e3da74"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html#ab6a385008493c7b630e4e7bc56e3da74">faiss::RangeSearchPartialResult::set_lims</a></div><divclass="ttdeci">void set_lims()</div><divclass="ttdoc">called by range_search before do_allocation </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00159">AuxIndexStructures.cpp:159</a></div></div>
<divclass="ttc"id="structfaiss_1_1DistanceComputer_html_a4d71be87bbd904043f6bc2fae03d037f"><divclass="ttname"><ahref="structfaiss_1_1DistanceComputer.html#a4d71be87bbd904043f6bc2fae03d037f">faiss::DistanceComputer::operator()</a></div><divclass="ttdeci">virtual float operator()(idx_t i)=0</div><divclass="ttdoc">compute distance of vector i to current query </div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchResult_html_a56dca2b151bcf16f5d488aff321b9501"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchResult.html#a56dca2b151bcf16f5d488aff321b9501">faiss::RangeSearchResult::RangeSearchResult</a></div><divclass="ttdeci">RangeSearchResult(idx_t nq, bool alloc_lims=true)</div><divclass="ttdoc">lims must be allocated on input to range_search. </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00024">AuxIndexStructures.cpp:24</a></div></div>
<divclass="ttc"id="structfaiss_1_1Index_html_ad3f0d3071f987baabbdd3da4500c87ea"><divclass="ttname"><ahref="structfaiss_1_1Index.html#ad3f0d3071f987baabbdd3da4500c87ea">faiss::Index::idx_t</a></div><divclass="ttdeci">long idx_t</div><divclass="ttdoc">all indices are this type </div><divclass="ttdef"><b>Definition:</b><ahref="Index_8h_source.html#l00062">Index.h:62</a></div></div>
<divclass="ttc"id="structfaiss_1_1BufferList_html_af4d7ddcd77f328a12a7da89d8febe5d9"><divclass="ttname"><ahref="structfaiss_1_1BufferList.html#af4d7ddcd77f328a12a7da89d8febe5d9">faiss::BufferList::wp</a></div><divclass="ttdeci">size_t wp</div><divclass="ttdoc">write pointer in the last buffer. </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00116">AuxIndexStructures.h:116</a></div></div>
<divclass="ttc"id="structfaiss_1_1BufferList_html_aa17f17a53b45bb39b0724d6493ab33c9"><divclass="ttname"><ahref="structfaiss_1_1BufferList.html#aa17f17a53b45bb39b0724d6493ab33c9">faiss::BufferList::add</a></div><divclass="ttdeci">void add(idx_t id, float dis)</div><divclass="ttdoc">add one result, possibly appending a new buffer if needed </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00079">AuxIndexStructures.cpp:79</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html">faiss::RangeSearchPartialResult</a></div><divclass="ttdoc">the entries in the buffers are split per query </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00149">AuxIndexStructures.h:149</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html_ad323d8ea8914d9071aecff83f69ee8e4"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html#ad323d8ea8914d9071aecff83f69ee8e4">faiss::RangeSearchPartialResult::copy_result</a></div><divclass="ttdeci">void copy_result(bool incremental=false)</div><divclass="ttdoc">called by range_search after do_allocation </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00168">AuxIndexStructures.cpp:168</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html_a0ba199c22ed09aebb0f7238229b516e9"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html#a0ba199c22ed09aebb0f7238229b516e9">faiss::RangeSearchPartialResult::new_result</a></div><divclass="ttdeci">RangeQueryResult & new_result(idx_t qno)</div><divclass="ttdoc">begin a new result </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00137">AuxIndexStructures.cpp:137</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchResult_html_a39342ad2e9ad8b90f6e95dafd3287f49"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchResult.html#a39342ad2e9ad8b90f6e95dafd3287f49">faiss::RangeSearchResult::buffer_size</a></div><divclass="ttdeci">size_t buffer_size</div><divclass="ttdoc">size of the result buffers used </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00040">AuxIndexStructures.h:40</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeQueryResult_html_aed669959bc918d9a554f236d40789084"><divclass="ttname"><ahref="structfaiss_1_1RangeQueryResult.html#aed669959bc918d9a554f236d40789084">faiss::RangeQueryResult::add</a></div><divclass="ttdeci">void add(float dis, idx_t id)</div><divclass="ttdoc">called by search function to report a new result </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00122">AuxIndexStructures.cpp:122</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchResult_html_aa8ff848474a4cc16c5464cc4ec187824"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchResult.html#aa8ff848474a4cc16c5464cc4ec187824">faiss::RangeSearchResult::labels</a></div><divclass="ttdeci">idx_t * labels</div><divclass="ttdoc">result for query i is labels[lims[i]:lims[i+1]] </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8h_source.html#l00037">AuxIndexStructures.h:37</a></div></div>
<divclass="ttc"id="structfaiss_1_1RangeSearchPartialResult_html_a41aaed4f59e7a6a99e2a643dfff483f5"><divclass="ttname"><ahref="structfaiss_1_1RangeSearchPartialResult.html#a41aaed4f59e7a6a99e2a643dfff483f5">faiss::RangeSearchPartialResult::RangeSearchPartialResult</a></div><divclass="ttdeci">RangeSearchPartialResult(RangeSearchResult *res_in)</div><divclass="ttdoc">eventually the result will be stored in res_in </div><divclass="ttdef"><b>Definition:</b><ahref="AuxIndexStructures_8cpp_source.html#l00129">AuxIndexStructures.cpp:129</a></div></div>