| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [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 | |
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 17 | #include "stats_util.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace os { |
| 21 | namespace statsd { |
| 22 | |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 23 | // There is no existing hash function for the dimension key ("repeated KeyValuePair"). |
| 24 | // Temporarily use a string concatenation as the hashable key. |
| 25 | // TODO: Find a better hash function for std::vector<KeyValuePair>. |
| 26 | HashableDimensionKey getHashableKey(std::vector<KeyValuePair> keys) { |
| 27 | std::string flattened; |
| 28 | for (const KeyValuePair& pair : keys) { |
| 29 | flattened += std::to_string(pair.key()); |
| 30 | flattened += ":"; |
| 31 | switch (pair.value_case()) { |
| 32 | case KeyValuePair::ValueCase::kValueStr: |
| 33 | flattened += pair.value_str(); |
| 34 | break; |
| 35 | case KeyValuePair::ValueCase::kValueInt: |
| 36 | flattened += std::to_string(pair.value_int()); |
| 37 | break; |
| Chenjie Yu | d9dfda7 | 2017-12-11 17:41:20 -0800 | [diff] [blame] | 38 | case KeyValuePair::ValueCase::kValueLong: |
| 39 | flattened += std::to_string(pair.value_long()); |
| 40 | break; |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 41 | case KeyValuePair::ValueCase::kValueBool: |
| 42 | flattened += std::to_string(pair.value_bool()); |
| 43 | break; |
| 44 | case KeyValuePair::ValueCase::kValueFloat: |
| 45 | flattened += std::to_string(pair.value_float()); |
| 46 | break; |
| 47 | default: |
| 48 | break; |
| 49 | } |
| 50 | flattened += "|"; |
| 51 | } |
| 52 | return flattened; |
| 53 | } |
| 54 | |
| Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 55 | } // namespace statsd |
| 56 | } // namespace os |
| 57 | } // namespace android |