blob: bd6b0cd47eaf094b72580a8911450231c12c7130 [file] [log] [blame]
Yangster-mac9def8e32018-04-17 13:55:51 -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
17#pragma once
18
19#include <string>
20
21namespace android {
22namespace os {
23namespace statsd {
24
Tej Singh96058222020-07-31 23:49:39 -070025// Uses murmur2 hashing algorithm.
Yangster-mac9def8e32018-04-17 13:55:51 -070026extern uint32_t Hash32(const char *data, size_t n, uint32_t seed);
27extern uint64_t Hash64(const char* data, size_t n, uint64_t seed);
28
29inline uint32_t Hash32(const char *data, size_t n) {
30 return Hash32(data, n, 0xBEEF);
31}
32
33inline uint32_t Hash32(const std::string &input) {
34 return Hash32(input.data(), input.size());
35}
36
37inline uint64_t Hash64(const char* data, size_t n) {
38 return Hash64(data, n, 0xDECAFCAFFE);
39}
40
41inline uint64_t Hash64(const std::string& str) {
42 return Hash64(str.data(), str.size());
43}
44
45} // namespace statsd
46} // namespace os
47} // namespace android