1// Copyright 2016 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_BASE_HASHMAP_ENTRY_H_ 6#define V8_BASE_HASHMAP_ENTRY_H_ 7 8#include <cstdint> 9 10namespace v8 { 11namespace base { 12 13// HashMap entries are (key, value, hash) triplets, with a boolean indicating if 14// they are an empty entry. Some clients may not need to use the value slot 15// (e.g. implementers of sets, where the key is the value). 16template <typename Key, typename Value> 17struct TemplateHashMapEntry { 18 Key key; 19 Value value; 20 uint32_t hash; // The full hash value for key 21 22 TemplateHashMapEntry(Key key, Value value, uint32_t hash) 23 : key(key), value(value), hash(hash), exists_(true) {} 24 25 bool exists() const { return exists_; } 26 27 void clear() { exists_ = false; } 28 29 private: 30 bool exists_; 31}; 32 33// Specialization for pointer-valued keys 34template <typename Key, typename Value> 35struct TemplateHashMapEntry<Key*, Value> { 36 Key* key; 37 Value value; 38 uint32_t hash; // The full hash value for key 39 40 TemplateHashMapEntry(Key* key, Value value, uint32_t hash) 41 : key(key), value(value), hash(hash) {} 42 43 bool exists() const { return key != nullptr; } 44 45 void clear() { key = nullptr; } 46}; 47 48// TODO(leszeks): There could be a specialisation for void values (e.g. for 49// sets), which omits the value field 50 51} // namespace base 52} // namespace v8 53 54#endif // V8_BASE_HASHMAP_ENTRY_H_ 55