xref: /aosp_15_r20/external/icing/icing/index/iterator/doc-hit-info-iterator-all-document-id.h (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
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_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_ALL_DOCUMENT_ID_H_
16 #define ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_ALL_DOCUMENT_ID_H_
17 
18 #include <cstdint>
19 #include <string>
20 
21 #include "icing/text_classifier/lib3/utils/base/status.h"
22 #include "icing/absl_ports/str_cat.h"
23 #include "icing/index/iterator/doc-hit-info-iterator.h"
24 #include "icing/legacy/core/icing-string-util.h"
25 #include "icing/store/document-id.h"
26 
27 namespace icing {
28 namespace lib {
29 
30 // Iterator for all DocumentIds in range [0, document_id_limit_]: 0 inclusive,
31 // document_id_limit_ inclusive. Returns DocumentIds in descending order.
32 class DocHitInfoIteratorAllDocumentId : public DocHitInfoIterator {
33  public:
34   explicit DocHitInfoIteratorAllDocumentId(DocumentId document_id_limit);
35 
36   libtextclassifier3::Status Advance() override;
37 
38   libtextclassifier3::StatusOr<TrimmedNode> TrimRightMostNode() && override;
39 
MapChildren(const ChildrenMapper & mapper)40   void MapChildren(const ChildrenMapper& mapper) override {}
41 
GetCallStats()42   CallStats GetCallStats() const override {
43     return CallStats(
44         /*num_leaf_advance_calls_lite_index_in=*/0,
45         /*num_leaf_advance_calls_main_index_in=*/0,
46         /*num_leaf_advance_calls_integer_index_in=*/0,
47         /*num_leaf_advance_calls_no_index_in=*/document_id_limit_ -
48             current_document_id_,
49         /*num_blocks_inspected_in=*/0);
50   }
51 
ToString()52   std::string ToString() const override {
53     return IcingStringUtil::StringPrintf("(ALL document_id_limit:%d)",
54                                          document_id_limit_);
55   }
56 
57  private:
58   const DocumentId document_id_limit_;
59 
60   // An internal value for the iterator to track the current doc id.
61   DocumentId current_document_id_;
62 };
63 
64 }  // namespace lib
65 }  // namespace icing
66 
67 #endif  // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_ALL_DOCUMENT_ID_H_
68