• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef INCLUDE_PERFETTO_PUBLIC_FNV1A_H_
18 #define INCLUDE_PERFETTO_PUBLIC_FNV1A_H_
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 
23 #include "perfetto/public/compiler.h"
24 
PerfettoFnv1a(const void * data,size_t size)25 static inline uint64_t PerfettoFnv1a(const void* data, size_t size) {
26   const uint64_t kFnv1a64OffsetBasis = 0xcbf29ce484222325;
27   const uint64_t kFnv1a64Prime = 0x100000001b3;
28 
29   uint64_t value = kFnv1a64OffsetBasis;
30 
31   for (size_t i = 0; i < size; i++) {
32     value =
33         (value ^ PERFETTO_STATIC_CAST(const uint8_t*, data)[i]) * kFnv1a64Prime;
34   }
35   return value;
36 }
37 
38 #endif  // INCLUDE_PERFETTO_PUBLIC_FNV1A_H_
39