The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Lightning Fast Immutable.js Equality Checks with Hash Codes

Lightning Fast Immutable.js Equality Checks with Hash Codes

2:27
While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's content. If two iterables have the same content, their hash codes will be the same. It's worth noting that this technique is unsuitable for mission critical application development since there is a chance, however slight, that checksums like these might collide. This is outlined here: https://en.wikipedia.org/wiki/Collision_(computer_science)
Watch this lesson now
Avatar
egghead.io

While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's content. If two iterables have the same content, their hash codes will be the same. It's worth noting that this technique is unsuitable for mission critical application development since there is a chance, however slight, that checksums like these might collide. This is outlined here: https://en.wikipedia.org/wiki/Collision_(computer_science)

Avatar
Amir Baron

I am not sure this is the correct way of getting things fast.
Objects that have the same hashcode could be not equals, but objects that are equals must have the same hashcode.
The hashcode optimization is built in https://github.com/facebook/immutable-js/blob/master/src/utils/deepEqual.js#L22.
I think this lesson could lead to a bug.

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?