Home / Function/ hashCode() — react Function Reference

hashCode() — react Function Reference

Architecture documentation for the hashCode() function in colors.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  4056ac94_4f21_a519_314a_abca9704130e["hashCode()"]
  e8b75ea1_4270_75d6_defb_16c2f1811aef["colors.js"]
  4056ac94_4f21_a519_314a_abca9704130e -->|defined in| e8b75ea1_4270_75d6_defb_16c2f1811aef
  style 4056ac94_4f21_a519_314a_abca9704130e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-timeline/src/content-views/utils/colors.js lines 36–52

function hashCode(string: string): number {
  // Hash algorithm for substrings is described in "Über die Komplexität der Multiplikation in
  // eingeschränkten Branchingprogrammmodellen" by Woelfe.
  // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000
  const p = (1 << 30) * 4 - 5; // prime: 2^32 - 5
  const z = 0x5033d967; // 32 bits from random.org
  const z2 = 0x59d2f15d; // random odd 32 bit number
  let s = 0;
  let zi = 1;
  for (let i = 0; i < string.length; i++) {
    const xi = string.charCodeAt(i) * z2;
    s = (s + zi * xi) % p;
    zi = (zi * z) % p;
  }
  s = (s + zi * (p - 1)) % p;
  return Math.abs(s | 0);
}

Domain

Subdomains

Frequently Asked Questions

What does hashCode() do?
hashCode() is a function in the react codebase, defined in packages/react-devtools-timeline/src/content-views/utils/colors.js.
Where is hashCode() defined?
hashCode() is defined in packages/react-devtools-timeline/src/content-views/utils/colors.js at line 36.

Analyze Your Own Codebase

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

Try Supermodel Free