chromium/v8/src/heap/base/cached-unordered-map.h

// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_BASE_CACHED_UNORDERED_MAP_H_
#define V8_HEAP_BASE_CACHED_UNORDERED_MAP_H_

#include <unordered_map>

#include "src/base/functional.h"

namespace heap::base {

// A cached map that speeds up `operator[]` if used in LRU fashion.
template <typename _Key, typename _Value, typename _Hash = v8::base::hash<_Key>>
class CachedUnorderedMap final {
  using MapT = std::unordered_map<_Key, _Value, _Hash>;

 public:
  using Key = typename MapT::key_type;
  using Mapped = typename MapT::mapped_type;

  Mapped& operator[](const Key& key) {}

  typename MapT::size_type erase(const Key& key) {}

  // No iterator is cached in this class so an actual find() has to be executed
  // everytime.
  typename MapT::iterator find(const Key& key) {}

  typename MapT::iterator begin() {}
  typename MapT::iterator end() {}
  typename MapT::const_iterator begin() const {}
  typename MapT::const_iterator end() const {}

  void clear() {}

  bool empty() const {}

  MapT Take() {}

 private:
  Key last_key_ = nullptr;
  Mapped* last_mapped_ = nullptr;
  MapT map_;
};

}  // namespace heap::base

#endif  // V8_HEAP_BASE_CACHED_UNORDERED_MAP_H_