diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-03-23 14:28:51 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-03-23 14:30:36 +0000 |
commit | 45af929151818ec383951d3d8b5018f690df85df (patch) | |
tree | 644f92234baaced21ad1354a5b0fde3eec276a75 /searchlib | |
parent | 19c5bbc4a4babe52c0948a9c4c3bc5f6c1da7b85 (diff) |
simplify iterator
* now distance function handles cell type, so
iterator does not need to be templated on that.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp index cd8fd76e988..20d6daf25e2 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp @@ -29,7 +29,7 @@ is_compatible(const vespalib::eval::ValueType& lhs, * Keeps a heap of the K best hit distances. * Currently always does brute-force scanning, which is very expensive. **/ -template <bool strict, typename LCT, typename RCT> +template <bool strict> class NearestNeighborImpl : public NearestNeighborIterator { public: @@ -83,42 +83,23 @@ private: double _lastScore; }; -template <bool strict, typename LCT, typename RCT> -NearestNeighborImpl<strict, LCT, RCT>::~NearestNeighborImpl() = default; +template <bool strict> +NearestNeighborImpl<strict>::~NearestNeighborImpl() = default; namespace { -template<bool strict, typename LCT, typename RCT> -std::unique_ptr<NearestNeighborIterator> -create_impl(const NearestNeighborIterator::Params ¶ms) -{ - using NNI = NearestNeighborImpl<strict, LCT, RCT>; - return std::make_unique<NNI>(params); -} - -using Creator = std::unique_ptr<NearestNeighborIterator>(*)(const NearestNeighborIterator::Params ¶ms); - -template <bool strict> -struct CellTypeResolver -{ - template <typename LCT, typename RCT> - static Creator - get_fun() { return create_impl<strict, LCT, RCT>; } -}; - std::unique_ptr<NearestNeighborIterator> resolve_strict_LCT_RCT(bool strict, const NearestNeighborIterator::Params ¶ms) { CellType lct = params.queryTensor.fast_type().cell_type(); CellType rct = params.tensorAttribute.getTensorType().cell_type(); + if (lct != rct) abort(); if (strict) { - using Resolver = CellTypeResolver<true>; - auto fun = vespalib::tensor::select_2<Resolver>(lct, rct); - return fun(params); + using NNI = NearestNeighborImpl<true>; + return std::make_unique<NNI>(params); } else { - using Resolver = CellTypeResolver<false>; - auto fun = vespalib::tensor::select_2<Resolver>(lct, rct); - return fun(params); + using NNI = NearestNeighborImpl<false>; + return std::make_unique<NNI>(params); } } |