amethyst / hibitset

Hierarchical bit set container
Other
117 stars 32 forks source link

implementation of Hash for BitSet #64

Open EWurbel opened 11 months ago

EWurbel commented 11 months ago

I have several projects which uses collections of BitSet objects intensely, and I need to store them in hashsets or hashmaps (or store structures containing BitSet objects in hashsets or hashmaps). At this time this is not possible. I plan to clone the repo and implement it. If it is convincing I will probably make a pull request.

zesterer commented 11 months ago

I'm such a feature would be appreciated.

EWurbel commented 11 months ago

Hi. I've done the implementation of the Hash interface (this is quite simple, it's a matter of calling the hash() method on the layer0 slice). So the modification just adds 5 lines of code in lib.rs

Before issuing a pull request I have a question.

I coded a test program to test for the effectiveness of the default hashing algorithm (i.e. lack of collisions), both using raw hash values and restrictions over a certain number of bits. It works nicely, at last for my needs.

Could it be a good idea to incorporate this program in the crate, and if so, which status to use ? This is not really a test, not really a benchmark, perhaps an example ?

I wait for an advice on this before issuing a pull request.

zesterer commented 11 months ago

I'm not sure how useful that would be, but if you wish. Consumers of hash function shouldn't assume a lack of collisions: a hash function that always returns 0 is still a valid hash function.

EWurbel commented 11 months ago

You are right, I should not have said "lack of collisions", but minimization of the number of collisions. But you are right, this program was mainly for my own use. I'll prepare a pull request without it.