Can you recommend a quick way to generate an Hashcode for a BitArray of size N > 1k, in C# .Net Core 3.1?
I've looked around and found a few answers but were specific to scenario under 64 bits and about a decade old. The few candidates that I have so far are:
Convert to string and use GetHashCode(). I'm a bit worried about the memory and speed here
Split my BitArray by chunk of 64 bits, convert them to long, call GetHasCode() then combine their hash with
unchecked
{
int hash = 17;
hash = hash * 31 + firstLong.GetHashCode();
hash = hash * 31 + secondLong.GetHashCode();
// etc
return hash;
}
I'm not really sure how to split effectively my BitArray into long and it's allocating many object here too
- use Value tuple feature since C# 7: (myBitArray).GetHashCode(); I'm not sure how it will work to be honest, but it seems to work on the Stack only