• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 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_NUMERIC_INTEGER_INDEX_DATA_H_
16 #define ICING_INDEX_NUMERIC_INTEGER_INDEX_DATA_H_
17 
18 #include <cstdint>
19 
20 #include "icing/index/hit/hit.h"
21 #include "icing/schema/section.h"
22 #include "icing/store/document-id.h"
23 
24 namespace icing {
25 namespace lib {
26 
27 // Data wrapper to store BasicHit and key for integer index.
28 class IntegerIndexData {
29  public:
IntegerIndexData(SectionId section_id,DocumentId document_id,int64_t key)30   explicit IntegerIndexData(SectionId section_id, DocumentId document_id,
31                             int64_t key)
32       : basic_hit_(section_id, document_id), key_(key) {}
33 
IntegerIndexData()34   explicit IntegerIndexData() : basic_hit_(), key_(0) {}
35 
basic_hit()36   const BasicHit& basic_hit() const { return basic_hit_; }
37 
key()38   int64_t key() const { return key_; }
39 
is_valid()40   bool is_valid() const { return basic_hit_.is_valid(); }
41 
42   bool operator<(const IntegerIndexData& other) const {
43     return basic_hit_ < other.basic_hit_;
44   }
45 
46   bool operator==(const IntegerIndexData& other) const {
47     return basic_hit_ == other.basic_hit_ && key_ == other.key_;
48   }
49 
50  private:
51   BasicHit basic_hit_;
52   int64_t key_;
53 } __attribute__((packed));
54 static_assert(sizeof(IntegerIndexData) == 12, "");
55 
56 }  // namespace lib
57 }  // namespace icing
58 
59 #endif  // ICING_INDEX_NUMERIC_INTEGER_INDEX_DATA_H_
60