1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <cstddef> 21*795d594fSAndroid Build Coastguard Worker #include <cstdint> 22*795d594fSAndroid Build Coastguard Worker #include <utility> 23*795d594fSAndroid Build Coastguard Worker 24*795d594fSAndroid Build Coastguard Worker namespace art { 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker class DexFile; 27*795d594fSAndroid Build Coastguard Worker 28*795d594fSAndroid Build Coastguard Worker class DexFileReference { 29*795d594fSAndroid Build Coastguard Worker public: DexFileReference(const DexFile * file,uint32_t idx)30*795d594fSAndroid Build Coastguard Worker DexFileReference(const DexFile* file, uint32_t idx) : dex_file(file), index(idx) {} 31*795d594fSAndroid Build Coastguard Worker const DexFile* dex_file; 32*795d594fSAndroid Build Coastguard Worker uint32_t index; 33*795d594fSAndroid Build Coastguard Worker 34*795d594fSAndroid Build Coastguard Worker struct Comparator { operatorComparator35*795d594fSAndroid Build Coastguard Worker bool operator()(const DexFileReference& a, const DexFileReference& b) const { 36*795d594fSAndroid Build Coastguard Worker if (a.dex_file != b.dex_file) { 37*795d594fSAndroid Build Coastguard Worker return a.dex_file < b.dex_file; 38*795d594fSAndroid Build Coastguard Worker } 39*795d594fSAndroid Build Coastguard Worker return a.index < b.index; 40*795d594fSAndroid Build Coastguard Worker } 41*795d594fSAndroid Build Coastguard Worker }; 42*795d594fSAndroid Build Coastguard Worker }; 43*795d594fSAndroid Build Coastguard Worker 44*795d594fSAndroid Build Coastguard Worker // Default comparators, compares the indices, not the backing data. 45*795d594fSAndroid Build Coastguard Worker inline bool operator<(const DexFileReference& a, const DexFileReference& b) { 46*795d594fSAndroid Build Coastguard Worker return DexFileReference::Comparator()(a, b); 47*795d594fSAndroid Build Coastguard Worker } 48*795d594fSAndroid Build Coastguard Worker inline bool operator==(const DexFileReference& a, const DexFileReference& b) { 49*795d594fSAndroid Build Coastguard Worker return a.dex_file == b.dex_file && a.index == b.index; 50*795d594fSAndroid Build Coastguard Worker } 51*795d594fSAndroid Build Coastguard Worker inline bool operator!=(const DexFileReference& a, const DexFileReference& b) { 52*795d594fSAndroid Build Coastguard Worker return !(a == b); 53*795d594fSAndroid Build Coastguard Worker } 54*795d594fSAndroid Build Coastguard Worker 55*795d594fSAndroid Build Coastguard Worker } // namespace art 56*795d594fSAndroid Build Coastguard Worker 57*795d594fSAndroid Build Coastguard Worker namespace std { 58*795d594fSAndroid Build Coastguard Worker // Hash implementation used for std::set/std::map. Simply xor the hash of the dex-file and index 59*795d594fSAndroid Build Coastguard Worker template <> 60*795d594fSAndroid Build Coastguard Worker struct hash<art::DexFileReference> { 61*795d594fSAndroid Build Coastguard Worker size_t operator()(const art::DexFileReference& ref) const { 62*795d594fSAndroid Build Coastguard Worker return hash<decltype(ref.dex_file)>()(ref.dex_file) ^ 63*795d594fSAndroid Build Coastguard Worker hash<decltype(ref.index)>()(ref.index); 64*795d594fSAndroid Build Coastguard Worker } 65*795d594fSAndroid Build Coastguard Worker }; 66*795d594fSAndroid Build Coastguard Worker } // namespace std 67*795d594fSAndroid Build Coastguard Worker 68*795d594fSAndroid Build Coastguard Worker #endif // ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_ 69