faiss 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE.txt +1 -1
  4. data/ext/faiss/ext.cpp +1 -1
  5. data/ext/faiss/extconf.rb +5 -6
  6. data/ext/faiss/index_binary.cpp +76 -17
  7. data/ext/faiss/{index.cpp → index_rb.cpp} +108 -35
  8. data/ext/faiss/kmeans.cpp +12 -9
  9. data/ext/faiss/numo.hpp +11 -9
  10. data/ext/faiss/pca_matrix.cpp +10 -8
  11. data/ext/faiss/product_quantizer.cpp +14 -12
  12. data/ext/faiss/{utils.cpp → utils_rb.cpp} +10 -3
  13. data/ext/faiss/{utils.h → utils_rb.h} +6 -0
  14. data/lib/faiss/version.rb +1 -1
  15. data/lib/faiss.rb +1 -1
  16. data/vendor/faiss/faiss/AutoTune.cpp +130 -11
  17. data/vendor/faiss/faiss/AutoTune.h +14 -1
  18. data/vendor/faiss/faiss/Clustering.cpp +59 -10
  19. data/vendor/faiss/faiss/Clustering.h +12 -0
  20. data/vendor/faiss/faiss/IVFlib.cpp +31 -28
  21. data/vendor/faiss/faiss/Index.cpp +20 -8
  22. data/vendor/faiss/faiss/Index.h +25 -3
  23. data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +19 -24
  24. data/vendor/faiss/faiss/IndexBinary.cpp +1 -0
  25. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +9 -4
  26. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +45 -11
  27. data/vendor/faiss/faiss/IndexFastScan.cpp +35 -22
  28. data/vendor/faiss/faiss/IndexFastScan.h +10 -1
  29. data/vendor/faiss/faiss/IndexFlat.cpp +193 -136
  30. data/vendor/faiss/faiss/IndexFlat.h +16 -1
  31. data/vendor/faiss/faiss/IndexFlatCodes.cpp +46 -22
  32. data/vendor/faiss/faiss/IndexFlatCodes.h +7 -1
  33. data/vendor/faiss/faiss/IndexHNSW.cpp +24 -50
  34. data/vendor/faiss/faiss/IndexHNSW.h +14 -12
  35. data/vendor/faiss/faiss/IndexIDMap.cpp +1 -1
  36. data/vendor/faiss/faiss/IndexIVF.cpp +76 -49
  37. data/vendor/faiss/faiss/IndexIVF.h +14 -4
  38. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +11 -8
  39. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -2
  40. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +25 -14
  41. data/vendor/faiss/faiss/IndexIVFFastScan.h +26 -22
  42. data/vendor/faiss/faiss/IndexIVFFlat.cpp +10 -61
  43. data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +39 -111
  44. data/vendor/faiss/faiss/IndexIVFPQ.cpp +89 -147
  45. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +37 -5
  46. data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -1
  47. data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +42 -30
  48. data/vendor/faiss/faiss/IndexIVFRaBitQ.h +2 -2
  49. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +246 -97
  50. data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +32 -29
  51. data/vendor/faiss/faiss/IndexLSH.cpp +8 -6
  52. data/vendor/faiss/faiss/IndexLattice.cpp +29 -24
  53. data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -0
  54. data/vendor/faiss/faiss/IndexNSG.cpp +2 -1
  55. data/vendor/faiss/faiss/IndexNSG.h +0 -2
  56. data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +1 -1
  57. data/vendor/faiss/faiss/IndexPQ.cpp +19 -10
  58. data/vendor/faiss/faiss/IndexRaBitQ.cpp +26 -13
  59. data/vendor/faiss/faiss/IndexRaBitQ.h +2 -2
  60. data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +132 -78
  61. data/vendor/faiss/faiss/IndexRaBitQFastScan.h +14 -12
  62. data/vendor/faiss/faiss/IndexRefine.cpp +0 -30
  63. data/vendor/faiss/faiss/IndexShards.cpp +3 -4
  64. data/vendor/faiss/faiss/MetricType.h +16 -0
  65. data/vendor/faiss/faiss/VectorTransform.cpp +120 -0
  66. data/vendor/faiss/faiss/VectorTransform.h +23 -0
  67. data/vendor/faiss/faiss/clone_index.cpp +7 -4
  68. data/vendor/faiss/faiss/{cppcontrib/factory_tools.cpp → factory_tools.cpp} +1 -1
  69. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
  70. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +37 -11
  71. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +0 -28
  72. data/vendor/faiss/faiss/impl/ClusteringInitialization.cpp +367 -0
  73. data/vendor/faiss/faiss/impl/ClusteringInitialization.h +107 -0
  74. data/vendor/faiss/faiss/impl/CodePacker.cpp +4 -0
  75. data/vendor/faiss/faiss/impl/CodePacker.h +11 -3
  76. data/vendor/faiss/faiss/impl/CodePackerRaBitQ.cpp +83 -0
  77. data/vendor/faiss/faiss/impl/CodePackerRaBitQ.h +47 -0
  78. data/vendor/faiss/faiss/impl/FaissAssert.h +60 -2
  79. data/vendor/faiss/faiss/impl/HNSW.cpp +25 -34
  80. data/vendor/faiss/faiss/impl/HNSW.h +8 -6
  81. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +34 -27
  82. data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -1
  83. data/vendor/faiss/faiss/impl/NSG.cpp +6 -5
  84. data/vendor/faiss/faiss/impl/NSG.h +17 -7
  85. data/vendor/faiss/faiss/impl/Panorama.cpp +53 -46
  86. data/vendor/faiss/faiss/impl/Panorama.h +22 -6
  87. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +16 -5
  88. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +70 -58
  89. data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +92 -0
  90. data/vendor/faiss/faiss/impl/RaBitQUtils.h +93 -31
  91. data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +12 -28
  92. data/vendor/faiss/faiss/impl/RaBitQuantizer.h +3 -10
  93. data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +15 -41
  94. data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +0 -4
  95. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +14 -9
  96. data/vendor/faiss/faiss/impl/ResultHandler.h +131 -50
  97. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +67 -2358
  98. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +0 -2
  99. data/vendor/faiss/faiss/impl/VisitedTable.cpp +42 -0
  100. data/vendor/faiss/faiss/impl/VisitedTable.h +69 -0
  101. data/vendor/faiss/faiss/impl/expanded_scanners.h +158 -0
  102. data/vendor/faiss/faiss/impl/index_read.cpp +829 -471
  103. data/vendor/faiss/faiss/impl/index_read_utils.h +0 -1
  104. data/vendor/faiss/faiss/impl/index_write.cpp +17 -8
  105. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +47 -20
  106. data/vendor/faiss/faiss/impl/mapped_io.cpp +9 -2
  107. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +7 -2
  108. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +11 -3
  109. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +19 -13
  110. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +29 -21
  111. data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx2.h → pq_code_distance/pq_code_distance-avx2.cpp} +42 -215
  112. data/vendor/faiss/faiss/impl/{code_distance/code_distance-avx512.h → pq_code_distance/pq_code_distance-avx512.cpp} +68 -107
  113. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-generic.cpp +141 -0
  114. data/vendor/faiss/faiss/impl/pq_code_distance/pq_code_distance-inl.h +23 -0
  115. data/vendor/faiss/faiss/impl/{code_distance/code_distance-sve.h → pq_code_distance/pq_code_distance-sve.cpp} +57 -144
  116. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +9 -6
  117. data/vendor/faiss/faiss/impl/scalar_quantizer/codecs.h +121 -0
  118. data/vendor/faiss/faiss/impl/scalar_quantizer/distance_computers.h +136 -0
  119. data/vendor/faiss/faiss/impl/scalar_quantizer/quantizers.h +280 -0
  120. data/vendor/faiss/faiss/impl/scalar_quantizer/scanners.h +164 -0
  121. data/vendor/faiss/faiss/impl/scalar_quantizer/similarities.h +94 -0
  122. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp +455 -0
  123. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp +430 -0
  124. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-dispatch.h +329 -0
  125. data/vendor/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp +467 -0
  126. data/vendor/faiss/faiss/impl/scalar_quantizer/training.cpp +203 -0
  127. data/vendor/faiss/faiss/impl/scalar_quantizer/training.h +42 -0
  128. data/vendor/faiss/faiss/impl/simd_dispatch.h +139 -0
  129. data/vendor/faiss/faiss/impl/simd_result_handlers.h +18 -18
  130. data/vendor/faiss/faiss/index_factory.cpp +35 -16
  131. data/vendor/faiss/faiss/index_io.h +29 -3
  132. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +7 -4
  133. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +1 -1
  134. data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +9 -19
  135. data/vendor/faiss/faiss/svs/IndexSVSFlat.h +2 -0
  136. data/vendor/faiss/faiss/svs/IndexSVSVamana.h +2 -1
  137. data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +9 -1
  138. data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +9 -0
  139. data/vendor/faiss/faiss/utils/Heap.cpp +46 -0
  140. data/vendor/faiss/faiss/utils/Heap.h +21 -0
  141. data/vendor/faiss/faiss/utils/NeuralNet.cpp +10 -7
  142. data/vendor/faiss/faiss/utils/distances.cpp +141 -23
  143. data/vendor/faiss/faiss/utils/distances.h +98 -0
  144. data/vendor/faiss/faiss/utils/distances_dispatch.h +170 -0
  145. data/vendor/faiss/faiss/utils/distances_simd.cpp +74 -3511
  146. data/vendor/faiss/faiss/utils/extra_distances-inl.h +164 -157
  147. data/vendor/faiss/faiss/utils/extra_distances.cpp +52 -95
  148. data/vendor/faiss/faiss/utils/extra_distances.h +47 -1
  149. data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +0 -1
  150. data/vendor/faiss/faiss/utils/partitioning.cpp +1 -1
  151. data/vendor/faiss/faiss/utils/pq_code_distance.h +251 -0
  152. data/vendor/faiss/faiss/utils/rabitq_simd.h +260 -0
  153. data/vendor/faiss/faiss/utils/simd_impl/distances_aarch64.cpp +150 -0
  154. data/vendor/faiss/faiss/utils/simd_impl/distances_arm_sve.cpp +568 -0
  155. data/vendor/faiss/faiss/utils/simd_impl/distances_autovec-inl.h +153 -0
  156. data/vendor/faiss/faiss/utils/simd_impl/distances_avx2.cpp +1185 -0
  157. data/vendor/faiss/faiss/utils/simd_impl/distances_avx512.cpp +1092 -0
  158. data/vendor/faiss/faiss/utils/simd_impl/distances_sse-inl.h +391 -0
  159. data/vendor/faiss/faiss/utils/simd_levels.cpp +322 -0
  160. data/vendor/faiss/faiss/utils/simd_levels.h +91 -0
  161. data/vendor/faiss/faiss/utils/simdlib_avx2.h +12 -1
  162. data/vendor/faiss/faiss/utils/simdlib_avx512.h +69 -0
  163. data/vendor/faiss/faiss/utils/simdlib_neon.h +6 -0
  164. data/vendor/faiss/faiss/utils/sorting.cpp +4 -4
  165. data/vendor/faiss/faiss/utils/utils.cpp +16 -9
  166. metadata +47 -18
  167. data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +0 -81
  168. data/vendor/faiss/faiss/impl/code_distance/code_distance.h +0 -186
  169. /data/vendor/faiss/faiss/{cppcontrib/factory_tools.h → factory_tools.h} +0 -0
@@ -12,16 +12,42 @@
12
12
  #pragma once
13
13
 
14
14
  #include <faiss/impl/AuxIndexStructures.h>
15
+ #include <faiss/impl/FaissAssert.h>
15
16
  #include <faiss/impl/FaissException.h>
16
17
  #include <faiss/impl/IDSelector.h>
17
18
  #include <faiss/utils/Heap.h>
18
19
  #include <faiss/utils/partitioning.h>
19
-
20
20
  #include <algorithm>
21
21
  #include <iostream>
22
22
 
23
23
  namespace faiss {
24
24
 
25
+ /* result handlers for a single query */
26
+
27
+ template <typename T, typename TI>
28
+ struct ResultHandlerUnordered {
29
+ // if not better than threshold, then not necessary to call add_result
30
+ T threshold{};
31
+
32
+ // return whether threshold was updated
33
+ virtual bool add_result(T dis, TI idx) = 0;
34
+
35
+ virtual ~ResultHandlerUnordered() {}
36
+ };
37
+
38
+ // handler for a single query
39
+ template <class C>
40
+ struct ResultHandlerT : ResultHandlerUnordered<typename C::T, typename C::TI> {
41
+ ResultHandlerT() {
42
+ this->threshold = C::neutral();
43
+ }
44
+
45
+ virtual ~ResultHandlerT() {}
46
+ };
47
+
48
+ // generic handler for searching in float indexes
49
+ using ResultHandler = ResultHandlerUnordered<float, idx_t>;
50
+
25
51
  /*****************************************************************
26
52
  * The classes below are intended to be used as template arguments
27
53
  * they handle results for batches of queries (size nq).
@@ -67,16 +93,46 @@ struct BlockResultHandler {
67
93
  }
68
94
  };
69
95
 
70
- // handler for a single query
71
- template <class C>
72
- struct ResultHandler {
73
- // if not better than threshold, then not necessary to call add_result
74
- typename C::T threshold = C::neutral();
96
+ /*****************************************************************
97
+ * Convenience classes for float Indexes
98
+ *****************************************************************/
75
99
 
76
- // return whether threshold was updated
77
- virtual bool add_result(typename C::T dis, typename C::TI idx) = 0;
100
+ // fake BlockResultHandler for a single query
101
+ template <class C, bool use_sel>
102
+ struct SingleQueryBlockResultHandler : BlockResultHandler<C, use_sel> {
103
+ using T = typename C::T;
104
+ using TI = typename C::TI;
105
+ using BlockResultHandler<C, use_sel>::i0;
106
+ using BlockResultHandler<C, use_sel>::i1;
107
+
108
+ ResultHandler& the_handler;
109
+
110
+ explicit SingleQueryBlockResultHandler(
111
+ ResultHandler& the_handler,
112
+ const IDSelector* sel = nullptr)
113
+ : BlockResultHandler<C, use_sel>(1, sel),
114
+ the_handler(the_handler) {}
115
+
116
+ struct SingleResultHandler : ResultHandlerT<C> {
117
+ ResultHandler& the_handler;
118
+ using ResultHandlerT<C>::threshold;
119
+
120
+ explicit SingleResultHandler(SingleQueryBlockResultHandler& hr)
121
+ : the_handler(hr.the_handler) {}
122
+
123
+ /// begin results for query # i
124
+ void begin(const size_t qid) {
125
+ assert(qid == 0);
126
+ }
127
+
128
+ /// add one result for query i
129
+ bool add_result(T dis, TI idx) final {
130
+ return the_handler.add_result(dis, idx);
131
+ }
78
132
 
79
- virtual ~ResultHandler() {}
133
+ /// series of results for query i is done
134
+ void end() {}
135
+ };
80
136
  };
81
137
 
82
138
  /*****************************************************************
@@ -127,9 +183,9 @@ struct Top1BlockResultHandler : TopkBlockResultHandler<C, use_sel> {
127
183
  : TopkBlockResultHandler<C, use_sel>(nq, dis_tab, ids_tab, 1, sel) {
128
184
  }
129
185
 
130
- struct SingleResultHandler : ResultHandler<C> {
186
+ struct SingleResultHandler : ResultHandlerT<C> {
131
187
  Top1BlockResultHandler& hr;
132
- using ResultHandler<C>::threshold;
188
+ using ResultHandlerT<C>::threshold;
133
189
 
134
190
  TI min_idx;
135
191
  size_t current_idx = 0;
@@ -204,6 +260,34 @@ struct Top1BlockResultHandler : TopkBlockResultHandler<C, use_sel> {
204
260
  * Heap based result handler
205
261
  *****************************************************************/
206
262
 
263
+ template <class C, bool use_sel = false>
264
+ struct HeapResultHandler : ResultHandlerT<C> {
265
+ using T = typename C::T;
266
+ using TI = typename C::TI;
267
+ using ResultHandlerT<C>::threshold;
268
+ size_t k;
269
+
270
+ T* heap_dis;
271
+ TI* heap_ids;
272
+
273
+ HeapResultHandler(size_t k, T* heap_dis, TI* heap_ids)
274
+ : k(k), heap_dis(heap_dis), heap_ids(heap_ids) {
275
+ if (heap_dis) {
276
+ this->threshold = heap_dis[0];
277
+ }
278
+ }
279
+
280
+ /// add one result for query i
281
+ bool add_result(T dis, TI idx) final {
282
+ if (C::cmp(threshold, dis)) {
283
+ heap_replace_top<C>(k, heap_dis, heap_ids, dis, idx);
284
+ threshold = heap_dis[0];
285
+ return true;
286
+ }
287
+ return false;
288
+ }
289
+ };
290
+
207
291
  template <class C, bool use_sel = false>
208
292
  struct HeapBlockResultHandler : TopkBlockResultHandler<C, use_sel> {
209
293
  using T = typename C::T;
@@ -220,43 +304,30 @@ struct HeapBlockResultHandler : TopkBlockResultHandler<C, use_sel> {
220
304
  const IDSelector* sel = nullptr)
221
305
  : TopkBlockResultHandler<C, use_sel>(nq, dis_tab, ids_tab, k, sel) {
222
306
  }
307
+
223
308
  /******************************************************
224
309
  * API for 1 result at a time (each SingleResultHandler is
225
310
  * called from 1 thread)
226
311
  */
227
312
 
228
- struct SingleResultHandler : ResultHandler<C> {
313
+ struct SingleResultHandler : HeapResultHandler<C, use_sel> {
229
314
  HeapBlockResultHandler& hr;
230
- using ResultHandler<C>::threshold;
231
- size_t k;
232
-
233
- T* heap_dis;
234
- TI* heap_ids;
235
315
 
236
316
  explicit SingleResultHandler(HeapBlockResultHandler& hr)
237
- : hr(hr), k(hr.k) {}
317
+ : HeapResultHandler<C, use_sel>(hr.k, nullptr, nullptr),
318
+ hr(hr) {}
238
319
 
239
320
  /// begin results for query # i
240
321
  void begin(size_t i) {
241
- heap_dis = hr.dis_tab + i * k;
242
- heap_ids = hr.ids_tab + i * k;
243
- heap_heapify<C>(k, heap_dis, heap_ids);
244
- threshold = heap_dis[0];
245
- }
246
-
247
- /// add one result for query i
248
- bool add_result(T dis, TI idx) final {
249
- if (C::cmp(threshold, dis)) {
250
- heap_replace_top<C>(k, heap_dis, heap_ids, dis, idx);
251
- threshold = heap_dis[0];
252
- return true;
253
- }
254
- return false;
322
+ this->heap_dis = hr.dis_tab + i * this->k;
323
+ this->heap_ids = hr.ids_tab + i * this->k;
324
+ heap_heapify<C>(this->k, this->heap_dis, this->heap_ids);
325
+ this->threshold = this->heap_dis[0];
255
326
  }
256
327
 
257
328
  /// series of results for query i is done
258
329
  void end() {
259
- heap_reorder<C>(k, heap_dis, heap_ids);
330
+ heap_reorder<C>(this->k, this->heap_dis, this->heap_ids);
260
331
  }
261
332
  };
262
333
 
@@ -312,10 +383,10 @@ struct HeapBlockResultHandler : TopkBlockResultHandler<C, use_sel> {
312
383
 
313
384
  /// Reservoir for a single query
314
385
  template <class C>
315
- struct ReservoirTopN : ResultHandler<C> {
386
+ struct ReservoirTopN : ResultHandlerT<C> {
316
387
  using T = typename C::T;
317
388
  using TI = typename C::TI;
318
- using ResultHandler<C>::threshold;
389
+ using ResultHandlerT<C>::threshold;
319
390
 
320
391
  T* vals;
321
392
  TI* ids;
@@ -488,6 +559,27 @@ struct ReservoirBlockResultHandler : TopkBlockResultHandler<C, use_sel> {
488
559
  * Result handler for range searches
489
560
  *****************************************************************/
490
561
 
562
+ template <class C, bool use_sel = false>
563
+ struct RangeResultHandler : ResultHandlerT<C> {
564
+ using T = typename C::T;
565
+ using TI = typename C::TI;
566
+ using ResultHandlerT<C>::threshold;
567
+
568
+ RangeQueryResult* qr = nullptr;
569
+
570
+ RangeResultHandler(RangeQueryResult* qr, T threshold) : qr(qr) {
571
+ this->threshold = threshold;
572
+ }
573
+
574
+ /// add one result for query i
575
+ bool add_result(T dis, TI idx) final {
576
+ if (C::cmp(threshold, dis)) {
577
+ qr->add(dis, idx);
578
+ }
579
+ return false;
580
+ }
581
+ };
582
+
491
583
  template <class C, bool use_sel = false>
492
584
  struct RangeSearchBlockResultHandler : BlockResultHandler<C, use_sel> {
493
585
  using T = typename C::T;
@@ -511,28 +603,17 @@ struct RangeSearchBlockResultHandler : BlockResultHandler<C, use_sel> {
511
603
  * called from 1 thread)
512
604
  ******************************************************/
513
605
 
514
- struct SingleResultHandler : ResultHandler<C> {
606
+ struct SingleResultHandler : RangeResultHandler<C> {
515
607
  // almost the same interface as RangeSearchResultHandler
516
- using ResultHandler<C>::threshold;
608
+ using ResultHandlerT<C>::threshold;
517
609
  RangeSearchPartialResult pres;
518
- RangeQueryResult* qr = nullptr;
519
610
 
520
611
  explicit SingleResultHandler(RangeSearchBlockResultHandler& rh)
521
- : pres(rh.res) {
522
- threshold = rh.radius;
523
- }
612
+ : RangeResultHandler<C>(nullptr, rh.radius), pres(rh.res) {}
524
613
 
525
614
  /// begin results for query # i
526
615
  void begin(size_t i) {
527
- qr = &pres.new_result(i);
528
- }
529
-
530
- /// add one result for query i
531
- bool add_result(T dis, TI idx) final {
532
- if (C::cmp(threshold, dis)) {
533
- qr->add(dis, idx);
534
- }
535
- return false;
616
+ this->qr = &pres.new_result(i);
536
617
  }
537
618
 
538
619
  /// series of results for query i is done