If you're hashing an array of bits:
You could implement a Cyclic redundancy check.
The CRC polynomial would determine the hash length and would (roughly) control the likelihood of a collision. Many example software CRC algorithms are optimized to operate on things wider than bits, but the core, un-optimized algorithm works a bit at a time. The algorithm is roughly:
- Start with some constant seed value in the accumulator
- Shift a bit from your array into the accumulator.
- Conditionally, perform an XOR with the polynomial. Different implementations either use the bit you just shifted out, the bit you just shifted in for the conditional.
- Repeat for subsequent bits (Goto 2).
Your proposed method would take the current accumulator value as the 1st argument, and return the next accumulator value.
Polynomial selection is important. There are some polynomials that are not considered good for hashing.
If the array contains something a little wider (like ints or objects):
You could just hash each element, and combine the hash of each element together with something like XOR. If the hash algorithm for the individual objects is good, then the resulting hash for the array should be relatively ok too. Note that it's very important to hash the individual objects first.