json-rust icon indicating copy to clipboard operation
json-rust copied to clipboard

`Hash` implementation

Open timothee-haudebourg opened this issue 4 years ago • 4 comments

I need to organize JsonValues into a HashSet however I just noticed that JsonValue does not implement the Hash trait. Is there a reason for that?

timothee-haudebourg avatar Mar 17 '20 15:03 timothee-haudebourg

Going deeper, I see that Object is implemented as a Binary tree, so there is a defined order between the keys of an object. Then I see no reason why it would not be possible to define an order between every JSON value? And a Hash?

timothee-haudebourg avatar Mar 17 '20 15:03 timothee-haudebourg

The keys are sorted into a tree, but the tree will be balanced differently depending on insertion order, so hashes would differ. If you are fine with matching objects with keys at insertion order then adding Hash impl should be pretty straight forward (at least in the new implementation, which is much cleaner, though still quite a bit in flux).

maciejhirsz avatar Mar 17 '20 21:03 maciejhirsz

When can we expect this new implementation to be released? Can we follow its development somewhere?

timothee-haudebourg avatar Aug 19 '21 12:08 timothee-haudebourg

Even if Object does not have a defined order, it is still possible to create a Hash implementation for it.

See https://github.com/rust-lang/rust/pull/48366 for an implementation of Hash on an unordered data structure.

A248 avatar Jan 19 '22 00:01 A248