blob: 7527a6455b05678505d15cd594ae9a94ddec51b2 [file] [log] [blame]
Yao Chencaf339d2017-10-06 16:01:10 -07001/*
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 Chencaf339d2017-10-06 16:01:10 -070017#include "stats_util.h"
18
19namespace android {
20namespace os {
21namespace statsd {
22
Yao Chen729093d2017-10-16 10:33:26 -070023// 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>.
26HashableDimensionKey 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 Yud9dfda72017-12-11 17:41:20 -080038 case KeyValuePair::ValueCase::kValueLong:
39 flattened += std::to_string(pair.value_long());
40 break;
Yao Chen729093d2017-10-16 10:33:26 -070041 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 Chencaf339d2017-10-06 16:01:10 -070055} // namespace statsd
56} // namespace os
57} // namespace android