Home / Class/ LRUCache Class — react Architecture

LRUCache Class — react Architecture

Architecture documentation for the LRUCache class in RunReactCompiler.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  a50d46f2_b369_20a9_cf24_127b30c7ff97["LRUCache"]
  93161a4a_8836_f386_2264_41352eee2303["RunReactCompiler.ts"]
  a50d46f2_b369_20a9_cf24_127b30c7ff97 -->|defined in| 93161a4a_8836_f386_2264_41352eee2303
  c94cb587_6179_92f3_bf01_adb5b7538451["constructor()"]
  a50d46f2_b369_20a9_cf24_127b30c7ff97 -->|method| c94cb587_6179_92f3_bf01_adb5b7538451
  0fac09e7_822b_b88a_a5c9_de0dee6ca194["get()"]
  a50d46f2_b369_20a9_cf24_127b30c7ff97 -->|method| 0fac09e7_822b_b88a_a5c9_de0dee6ca194
  82cff55e_c62f_83e0_0695_7a9f132d4b4e["push()"]
  a50d46f2_b369_20a9_cf24_127b30c7ff97 -->|method| 82cff55e_c62f_83e0_0695_7a9f132d4b4e

Relationship Graph

Source Code

compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts lines 162–196

class LRUCache<K, T> {
  // newest at headIdx, then headIdx + 1, ..., tailIdx
  #values: Array<[K, T | Error] | [typeof SENTINEL, void]>;
  #headIdx: number = 0;

  constructor(size: number) {
    this.#values = new Array(size).fill(SENTINEL);
  }

  // gets a value and sets it as "recently used"
  get(key: K): T | null {
    let idx = this.#values.findIndex(entry => entry[0] === key);
    // If found, move to front
    if (idx === this.#headIdx) {
      return this.#values[this.#headIdx][1] as T;
    } else if (idx < 0) {
      return null;
    }

    const entry: [K, T] = this.#values[idx] as [K, T];

    const len = this.#values.length;
    for (let i = 0; i < Math.min(idx, len - 1); i++) {
      this.#values[(this.#headIdx + i + 1) % len] =
        this.#values[(this.#headIdx + i) % len];
    }
    this.#values[this.#headIdx] = entry;
    return entry[1];
  }
  push(key: K, value: T): void {
    this.#headIdx =
      (this.#headIdx - 1 + this.#values.length) % this.#values.length;
    this.#values[this.#headIdx] = [key, value];
  }
}

Domain

Frequently Asked Questions

What is the LRUCache class?
LRUCache is a class in the react codebase, defined in compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts.
Where is LRUCache defined?
LRUCache is defined in compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts at line 162.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free