Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Hash typeclass improvements #194

Merged
merged 9 commits into from
Aug 15, 2020
Merged

Hash typeclass improvements #194

merged 9 commits into from
Aug 15, 2020

Conversation

1Jajen1
Copy link
Member

@1Jajen1 1Jajen1 commented Jul 24, 2020

I made a few changes to the Hash typeclass to make it both easier to define and better to use.

  • Removed the Eq superclass from it. It never made sense and it should not have been there in the first place.
  • Added hashWithSalt. Allows for two nice things: First hashing with salt, but also allows very easy definitions for sum types: Either<L, R>.hash(HL: Hash<L>, HR: Hash<R>): Int = fold({ l -> HL.run { l.hashWithSalt(0) } }, { r -> HR.run { r.hashWithSalt(1) } })
  • Added Hashed datatype. It carriers its precomputed hash and thus provides very fast inequality checks and provides its Hash instances with the cached hash.

Overall this makes Hash actually somewhat useful over the default hashCode now :)

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff for hashing 🙌 thanks @1Jajen1

@rachelcarmena
Copy link
Member

I removed the last merge with master branch because errors raised after solving the conflict. In this way, the conflict can be solved again @1Jajen1 😉

@rachelcarmena rachelcarmena merged commit 8d84f11 into master Aug 15, 2020
@rachelcarmena rachelcarmena deleted the jo-hash-rework branch August 15, 2020 20:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants