Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_HASH_H_
6#define RUNTIME_VM_HASH_H_
7
8#include "platform/globals.h"
9
10namespace dart {
11
12inline uint32_t CombineHashes(uint32_t hash, uint32_t other_hash) {
13 // Keep in sync with AssemblerBase::CombineHashes.
14 hash += other_hash;
15 hash += hash << 10;
16 hash ^= hash >> 6; // Logical shift, unsigned hash.
17 return hash;
18}
19
20inline uint32_t FinalizeHash(uint32_t hash, intptr_t hashbits = kBitsPerInt32) {
21 // Keep in sync with AssemblerBase::FinalizeHash.
22 hash += hash << 3;
23 hash ^= hash >> 11; // Logical shift, unsigned hash.
24 hash += hash << 15;
25 if (hashbits < kBitsPerInt32) {
26 hash &= (static_cast<uint32_t>(1) << hashbits) - 1;
27 }
28 return (hash == 0) ? 1 : hash;
29}
30
31inline uint32_t HashBytes(const uint8_t* bytes, intptr_t size) {
32 uint32_t hash = size;
33 while (size > 0) {
34 hash = CombineHashes(hash, *bytes);
35 bytes++;
36 size--;
37 }
38 return hash;
39}
40
41} // namespace dart
42
43#endif // RUNTIME_VM_HASH_H_
static uint32_t hash(const SkShaderBase::GradientInfo &v)
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
Definition hash.h:12
uint32_t HashBytes(const uint8_t *bytes, intptr_t size)
Definition hash.h:31
constexpr intptr_t kBitsPerInt32
Definition globals.h:466
uint32_t FinalizeHash(uint32_t hash, intptr_t hashbits=kBitsPerInt32)
Definition hash.h:20