xref: /aosp_15_r20/external/icing/icing/result/projection-tree.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_RESULT_PROJECTION_TREE_H_
16 #define ICING_RESULT_PROJECTION_TREE_H_
17 
18 #include <string_view>
19 #include <vector>
20 
21 #include "icing/proto/search.pb.h"
22 #include "icing/schema/schema-store.h"
23 
24 namespace icing {
25 namespace lib {
26 
27 class ProjectionTree {
28  public:
29   struct Node {
nameNode30     explicit Node(std::string name = "") : name(std::move(name)) {}
31 
32     std::string name;
33     std::vector<Node> children;
34 
35     bool operator==(const Node& other) const {
36       return name == other.name && children == other.children;
37     }
38   };
39 
40   explicit ProjectionTree(
41       const SchemaStore::ExpandedTypePropertyMask& type_field_mask);
42 
root()43   const Node& root() const { return root_; }
44 
45   bool operator==(const ProjectionTree& other) const {
46     return root_ == other.root_;
47   }
48 
49  private:
50   // Add a child node with property_name to current_children and returns a
51   // pointer to the child node.
52   Node* AddChildNode(std::string_view property_name,
53                      std::vector<Node>* current_children);
54 
55   Node root_;
56 };
57 
58 }  // namespace lib
59 }  // namespace icing
60 
61 #endif  // ICING_RESULT_PROJECTION_TREE_H_
62