xref: /aosp_15_r20/external/icing/icing/store/document-filter-data.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_STORE_DOCUMENT_FILTER_DATA_H_
16 #define ICING_STORE_DOCUMENT_FILTER_DATA_H_
17 
18 #include <cstdint>
19 #include <type_traits>
20 
21 #include "icing/legacy/core/icing-packed-pod.h"
22 #include "icing/store/namespace-id.h"
23 
24 namespace icing {
25 namespace lib {
26 
27 using SchemaTypeId = int16_t;
28 inline constexpr SchemaTypeId kInvalidSchemaTypeId = -1;
29 
30 class DocumentFilterData {
31  public:
DocumentFilterData(NamespaceId namespace_id,uint64_t uri_fingerprint,SchemaTypeId schema_type_id,int64_t expiration_timestamp_ms)32   explicit DocumentFilterData(NamespaceId namespace_id,
33                               uint64_t uri_fingerprint,
34                               SchemaTypeId schema_type_id,
35                               int64_t expiration_timestamp_ms)
36       : expiration_timestamp_ms_(expiration_timestamp_ms),
37         uri_fingerprint_(uri_fingerprint),
38         namespace_id_(namespace_id),
39         schema_type_id_(schema_type_id) {}
40 
41   bool operator==(const DocumentFilterData& other) const {
42     return namespace_id_ == other.namespace_id() &&
43            uri_fingerprint_ == other.uri_fingerprint() &&
44            schema_type_id_ == other.schema_type_id() &&
45            expiration_timestamp_ms_ == other.expiration_timestamp_ms();
46   }
47 
namespace_id()48   NamespaceId namespace_id() const { return namespace_id_; }
49 
uri_fingerprint()50   uint64_t uri_fingerprint() const { return uri_fingerprint_; }
51 
schema_type_id()52   SchemaTypeId schema_type_id() const { return schema_type_id_; }
set_schema_type_id(SchemaTypeId schema_type_id)53   void set_schema_type_id(SchemaTypeId schema_type_id) {
54     schema_type_id_ = schema_type_id;
55   }
56 
expiration_timestamp_ms()57   int64_t expiration_timestamp_ms() const { return expiration_timestamp_ms_; }
58 
59  private:
60   int64_t expiration_timestamp_ms_;
61   uint64_t uri_fingerprint_;
62   NamespaceId namespace_id_;
63   SchemaTypeId schema_type_id_;
64 } __attribute__((packed));
65 
66 static_assert(sizeof(DocumentFilterData) == 20, "");
67 static_assert(icing_is_packed_pod<DocumentFilterData>::value, "go/icing-ubsan");
68 
69 }  // namespace lib
70 }  // namespace icing
71 
72 #endif  // ICING_STORE_DOCUMENT_FILTER_DATA_H_
73