Skip to content

Weaken AlgebraicValue's Hash function to ignore enum discriminants #1048

@Centril

Description

@Centril

The current implementation of AlgebraicValue is #[derive(Hash)].
This causes the hash function to hash like so for e.g., AlgebraicValue::U16(x) to be:

hasher.write_u8(8); // The discriminant of `AlgebraicValue::U16` is 8.
hasher.write_u16(x); // The actual value `x: u16` in `::U16`.

Instead, based on my discussion with @gefjon, we agreed that, we should only hash each AV's payload and not the tag/discriminant of the AV variant itself. The benefits include:

  1. This weakening should be more performant because its less work.
  2. This is what the hash function for RowRef already does.
  3. It's easier to define a hash function for BSATN-encoded rows this way.

The weakening should not introduce more collisions because AVs in e.g., subscriptions follow a schema, so when you have 100 ::U8s, it does not reduce the rate of collisions when you hash the tag of U8.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions