1 // Copyright (C) 2023 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 #include "icing/join/doc-join-info.h"
16
17 #include <cstdint>
18
19 #include "icing/schema/joinable-property.h"
20 #include "icing/store/document-id.h"
21 #include "icing/util/bit-util.h"
22
23 namespace icing {
24 namespace lib {
25
DocJoinInfo(DocumentId document_id,JoinablePropertyId joinable_property_id)26 DocJoinInfo::DocJoinInfo(DocumentId document_id,
27 JoinablePropertyId joinable_property_id) {
28 Value temp_value = 0;
29 bit_util::BitfieldSet(/*new_value=*/document_id,
30 /*lsb_offset=*/kJoinablePropertyIdBits,
31 /*len=*/kDocumentIdBits, &temp_value);
32 bit_util::BitfieldSet(/*new_value=*/joinable_property_id,
33 /*lsb_offset=*/0,
34 /*len=*/kJoinablePropertyIdBits, &temp_value);
35 value_ = temp_value;
36 }
37
document_id() const38 DocumentId DocJoinInfo::document_id() const {
39 return bit_util::BitfieldGet(value_, /*lsb_offset=*/kJoinablePropertyIdBits,
40 /*len=*/kDocumentIdBits);
41 }
42
joinable_property_id() const43 JoinablePropertyId DocJoinInfo::joinable_property_id() const {
44 return bit_util::BitfieldGet(value_, /*lsb_offset=*/0,
45 /*len=*/kJoinablePropertyIdBits);
46 }
47
48 } // namespace lib
49 } // namespace icing
50