sparsemat / sprs

sparse linear algebra library for rust
Apache License 2.0
386 stars 45 forks source link

Derive Hash on sparse storage containers #238

Closed maboesanman closed 3 years ago

maboesanman commented 3 years ago

It would be convenient for the sparse data structures in sprs to implement Hash, and deriving it should be fine.

This PR also adds Eq to CsVecBase.

maboesanman commented 3 years ago

I thought I needed this, but soon realized that I wouldn't be able to because I'm using vectors of floats, which don't implement hash...

The idea was to store my sparse vectors in a hash map because the calculation I am doing is likely to perform redundant calculations, so I look up the vector in a hashmap and skip the calculation if it's already present.

I ended up hashing the indices array because it was easier and a better balance of performance and optimization.

Still, the collections being hashable seems useful, even if it didn't pan out in my case

vbarrielle commented 3 years ago

I see. Thanks for the info. I also think being hashable for types other than floats can be useful.