blob: 85c317f8cf1f35f597332b70ffc8639b44d4b8cc [file] [log] [blame]
Yao Chend5aa01b32017-12-19 16:46:36 -08001/*
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
22namespace android {
23namespace os {
24namespace statsd {
25
26class HashableDimensionKey {
27public:
Yangster-mac20877162017-12-22 17:19:39 -080028 explicit HashableDimensionKey(const DimensionsValue& dimensionsValue)
29 : mDimensionsValue(dimensionsValue){};
Yao Chend5aa01b32017-12-19 16:46:36 -080030
31 HashableDimensionKey(){};
32
33 HashableDimensionKey(const HashableDimensionKey& that)
Yangster-mac20877162017-12-22 17:19:39 -080034 : mDimensionsValue(that.getDimensionsValue()){};
Yao Chend5aa01b32017-12-19 16:46:36 -080035
36 HashableDimensionKey& operator=(const HashableDimensionKey& from) = default;
37
38 std::string toString() const;
39
Yangster-mac20877162017-12-22 17:19:39 -080040 inline const DimensionsValue& getDimensionsValue() const {
41 return mDimensionsValue;
Yao Chend5aa01b32017-12-19 16:46:36 -080042 }
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
52private:
Yangster-mac20877162017-12-22 17:19:39 -080053 DimensionsValue mDimensionsValue;
Yao Chend5aa01b32017-12-19 16:46:36 -080054};
55
Yangster-mac94e197c2018-01-02 16:03:03 -080056android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value);
Yangster-mac20877162017-12-22 17:19:39 -080057android::hash_t hashDimensionsValue(const DimensionsValue& value);
58
Yao Chend5aa01b32017-12-19 16:46:36 -080059} // namespace statsd
60} // namespace os
61} // namespace android
62
63namespace std {
64
65using android::os::statsd::HashableDimensionKey;
Yao Chend5aa01b32017-12-19 16:46:36 -080066
67template <>
68struct hash<HashableDimensionKey> {
69 std::size_t operator()(const HashableDimensionKey& key) const {
Yangster-mac20877162017-12-22 17:19:39 -080070 return hashDimensionsValue(key.getDimensionsValue());
Yao Chend5aa01b32017-12-19 16:46:36 -080071 }
72};
73
74} // namespace std