liangsun/simhash — pull request #2 by dlebech (2014-03-14 08:45:13+00:00)
Title: Refactor SimhashIndex buckets to support arbitrary bitlength

This pull request refactors the bucket key calculation for SimhashIndex into its own method which now support arbitrary bit-length instead of just 64 bit.

I am not terribly strong with numbers so I made two *guesses* about what is going on in your bucket calculation:

1. The calculated offsets for the buckets where previously `[0, 21, 42]` which looked like they were basically intervals between 0 and 64 bits (64 // 3 = 21) so I based the offset calculation on that. For example, for 32 bit, the offsets will be `[0, 10, 20]`.
2. The two hex values `0x1fffff = 2**21-1` and `0x3fffff = 2**22-1` seem to be the low and high end of the middle interval value 21 so I based the calculation of them on this assumption.

List of changes:
* Move bucket key calculation from SimhashIndex to Simhash in order to take the
bit-length "f" into account when constructing the bucket keys for a simhash.
* Add tests for 32 bit Simhash and SimhashIndex.
* Add ValueError when measuring distance between Simhash of different bitlength.