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