• 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_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 
GetNumBlocksInspected()40   int32_t GetNumBlocksInspected() const override { return 0; }
41 
GetNumLeafAdvanceCalls()42   int32_t GetNumLeafAdvanceCalls() const override {
43     return document_id_limit_ - current_document_id_;
44   }
45 
ToString()46   std::string ToString() const override {
47     return IcingStringUtil::StringPrintf("(ALL document_id_limit:%d)",
48                                          document_id_limit_);
49   }
50 
51  private:
52   const DocumentId document_id_limit_;
53 
54   // An internal value for the iterator to track the current doc id.
55   DocumentId current_document_id_;
56 };
57 
58 }  // namespace lib
59 }  // namespace icing
60 
61 #endif  // ICING_INDEX_ITERATOR_DOC_HIT_INFO_ITERATOR_ALL_DOCUMENT_ID_H_
62