chromium/third_party/blink/renderer/core/css/fixed_size_cache.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_FIXED_SIZE_CACHE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_FIXED_SIZE_CACHE_H_

// A cache of fixed size, which will automatically evict members
// when there is no room for them. This is a simple 2-way associative
// cache; i.e., every element can go into one out of two neighboring
// slots. An inserted element is always overwriting whatever is in
// slot 1 (unless slot 0 is empty); on a successful lookup,
// it is moved to slot 0. This gives preference to the elements that are
// actually used, and the scheme is simple enough that it's faster than
// using a standard HashMap.
//
// There are no heap allocations after the initial setup. Deletions
// and overwrites (inserting the same key more than once) are not
// supported. Uses the given hash traits, so you should never try to
// insert or search for EmptyValue(). It can hold Oilpan members.

#include <stdint.h>
#include <algorithm>
#include <utility>

#include "base/check.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"

namespace blink {

template <class Key,
          class Value,
          class KeyTraits = HashTraits<Key>,
          unsigned cache_size = 512>
class FixedSizeCache {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_FIXED_SIZE_CACHE_H_