Misc. Querying Performance Improvements

Here lies a whole bunch of changes, mostly intended to make querying faster; see commit messages for details.

A comparison of old v. new:

![comparison](http://misc.tomn.co.uk/lsh_final_comparison.png)

Extrapolated performance stats assuming we don't run out of memory:

| store |  type  | time for size=700000 |
| ----- |  ----- | -------------------- |
|   old |   add  |           0.11834982 |
|   old | query  |          21.60059752 |
|   new |   add  |           0.06145964 |
|   new | query  |           2.19377981 |


-Tom