Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <utils/JenkinsHash.h> |
| 20 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
| 21 | |
| 22 | namespace android { |
| 23 | namespace os { |
| 24 | namespace statsd { |
| 25 | |
| 26 | class HashableDimensionKey { |
| 27 | public: |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 28 | explicit HashableDimensionKey(const DimensionsValue& dimensionsValue) |
| 29 | : mDimensionsValue(dimensionsValue){}; |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 30 | |
| 31 | HashableDimensionKey(){}; |
| 32 | |
| 33 | HashableDimensionKey(const HashableDimensionKey& that) |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 34 | : mDimensionsValue(that.getDimensionsValue()){}; |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 35 | |
| 36 | HashableDimensionKey& operator=(const HashableDimensionKey& from) = default; |
| 37 | |
| 38 | std::string toString() const; |
| 39 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 40 | inline const DimensionsValue& getDimensionsValue() const { |
| 41 | return mDimensionsValue; |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | bool operator==(const HashableDimensionKey& that) const; |
| 45 | |
| 46 | bool operator<(const HashableDimensionKey& that) const; |
| 47 | |
| 48 | inline const char* c_str() const { |
| 49 | return toString().c_str(); |
| 50 | } |
| 51 | |
| 52 | private: |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 53 | DimensionsValue mDimensionsValue; |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 56 | android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 57 | android::hash_t hashDimensionsValue(const DimensionsValue& value); |
| 58 | |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 59 | } // namespace statsd |
| 60 | } // namespace os |
| 61 | } // namespace android |
| 62 | |
| 63 | namespace std { |
| 64 | |
| 65 | using android::os::statsd::HashableDimensionKey; |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 66 | |
| 67 | template <> |
| 68 | struct hash<HashableDimensionKey> { |
| 69 | std::size_t operator()(const HashableDimensionKey& key) const { |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 70 | return hashDimensionsValue(key.getDimensionsValue()); |
Yao Chen | d5aa01b3 | 2017-12-19 16:46:36 -0800 | [diff] [blame] | 71 | } |
| 72 | }; |
| 73 | |
| 74 | } // namespace std |