Prowl icon indicating copy to clipboard operation
Prowl copied to clipboard

Feat: Prowlhash test suite

Open brmassa opened this issue 1 year ago • 4 comments

Prowlhash

  • Code optimization to avoid repetition (prone to errors)
  • Prowlhash Seed can be manually set
  • replace GetHashCode for a stable hash generator because GetHashCode is unpredictable on each run, Os and archteture.
  • 20+ unit tests to ensure it's quality

dependent on #177

brmassa avatar Sep 18 '24 10:09 brmassa

Could you explain the StableHash a bit more? Does this not expect values to always be strings, and how does it handle class references? GetHashCode is nice since two classes that are different instances return different HashCodes unless they override the function.

michaelsakharov avatar Sep 18 '24 14:09 michaelsakharov

GetHashCode: The default GetHashCode method in .NET can produce different hash codes for the same object in different runs of the application. This is because the default implementation may use the object's memory address, which can/will change between runs.

StableHash: The StableHash method aims to produce the same hash code for the same object across different runs. This is achieved by using a deterministic seed and by hashing the object's state rather than its memory address

brmassa avatar Sep 18 '24 17:09 brmassa

If im not mistaken StableHash works by the objects ability to convert to string? What about like classes that don't implement ToString()? It would fallback to the Type name and all instances would receive the same hash? And what if the implementation of ToString() isn't reliable for object's state?

Im not entirely against this it does make sense to have a stable option, just curious how this method behaves compared to the default GetHashCode. If that is the case it might be nice to support both, like GetHashCode(bool deterministic) or something, as I can see a few cases where just GetHashCode might be nice to have for having a unique "hash" per instance of a class (the memory address).

michaelsakharov avatar Sep 19 '24 05:09 michaelsakharov

Also if you don't mind me asking whats your original reasoning/intention for having a deterministic hashcode?

michaelsakharov avatar Sep 19 '24 05:09 michaelsakharov