• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_SCORING_RANKER_H_
16 #define ICING_SCORING_RANKER_H_
17 
18 #include <vector>
19 
20 #include "icing/scoring/scored-document-hit.h"
21 
22 // Provides functionality to get the top N results from an unsorted vector.
23 namespace icing {
24 namespace lib {
25 
26 // Builds a heap of scored document hits. The same vector is used to store the
27 // heap structure.
28 //
29 // REQUIRED: scored_document_hits is not null.
30 void BuildHeapInPlace(
31     std::vector<ScoredDocumentHit>* scored_document_hits,
32     const ScoredDocumentHitComparator& scored_document_hit_comparator);
33 
34 // Returns the top num_results results from the given heap and remove those
35 // results from the heap. An empty vector will be returned if heap is empty.
36 //
37 // REQUIRED: scored_document_hits_heap is not null.
38 std::vector<ScoredDocumentHit> PopTopResultsFromHeap(
39     std::vector<ScoredDocumentHit>* scored_document_hits_heap, int num_results,
40     const ScoredDocumentHitComparator& scored_document_hit_comparator);
41 
42 }  // namespace lib
43 }  // namespace icing
44 
45 #endif  // ICING_SCORING_RANKER_H_
46