Skip to content

Hash function uses counter as hash value for non-string types #379

@akezhanmussa

Description

@akezhanmussa

Context
While searching for a repo on the SWR framework in React to check the hash implementation for multiple argument passing, I came across a Vue repo on hash implementation by chance.

Problem
While reviewing the hash function implementation, I noticed that the hash value for object/function types seems incorrect. Basically, it assigns a counter as the hash value for these types. This means that if I pass a list of objects rather than strings as arguments, the resulting hash values would be the same.

if (!table.has(args[i])) {
  _hash = counter;
  table.set(args[i], counter++);
} else {
  _hash = table.get(args[i]);
}

For reference, here's the hash function from the SWR React implementation that recursively handles non-string types, please check the link.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions