v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
string-hasher.h
Go to the documentation of this file.
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_STRINGS_STRING_HASHER_H_
6#define V8_STRINGS_STRING_HASHER_H_
7
9
10namespace v8 {
11
12namespace base {
13template <typename T>
14class Vector;
15} // namespace base
16
17namespace internal {
18
19// A simple incremental string hasher. Slow but allows for special casing each
20// individual character.
22 public:
23 explicit RunningStringHasher(uint32_t seed) : running_hash_(seed) {}
24
25 V8_INLINE void AddCharacter(uint16_t c);
26 V8_INLINE uint32_t Finalize();
27
28 private:
29 uint32_t running_hash_;
30};
31
32// Helper class for incrementally calculating string hashes in a form suitable
33// for storing into Name::raw_hash_field.
35 public:
36 StringHasher() = delete;
37 template <typename char_t>
38 static inline uint32_t HashSequentialString(const char_t* chars,
39 uint32_t length, uint64_t seed);
40
41 // Calculated hash value for a string consisting of 1 to
42 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
43 // value is represented decimal value.
44 static V8_INLINE uint32_t MakeArrayIndexHash(uint32_t value, uint32_t length);
45
46 // No string is allowed to have a hash of zero. That value is reserved
47 // for internal properties. If the hash calculation yields zero then we
48 // use 27 instead.
49 static const int kZeroHash = 27;
50
51 static V8_INLINE uint32_t GetTrivialHash(uint32_t length);
52};
53
54// Useful for std containers that require something ()'able.
56 explicit SeededStringHasher(uint64_t hashseed) : hashseed_(hashseed) {}
57 inline std::size_t operator()(const char* name) const;
58
59 uint64_t hashseed_;
60};
61
62// Useful for std containers that require something ()'able.
64 bool operator()(const char* name1, const char* name2) const {
65 return strcmp(name1, name2) == 0;
66 }
67};
68
69} // namespace internal
70} // namespace v8
71
72#endif // V8_STRINGS_STRING_HASHER_H_
V8_INLINE void AddCharacter(uint16_t c)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
SeededStringHasher(uint64_t hashseed)
std::size_t operator()(const char *name) const
bool operator()(const char *name1, const char *name2) const
#define V8_INLINE
Definition v8config.h:500