Commit 8f413ebc authored by Tim McNamara's avatar Tim McNamara

Update hash-small-strings.md

parent 2f65b948
......@@ -4,12 +4,24 @@ functions when dealing with small strings? Things like the columns of databases
with business data, such as domain names, email addresses, city names and other
place names.
### xor/shift hash
I haven't done any background research or survey work. This has probably been
done many times. But I thought it would be worthwhile to see what I could achieve.
### XORlen hash
This needs a better name. We iterate through the input byte stream, treating it as an
iterator of 64-bit unsigned integers. Each new integer is XORed with a temporary variable.
A special case is made when there isn't enough data to make a full integer. In that
case, we pad with zeros.
As a final step, the temporary variable is XORed with the number of bytes that
have been processed through the byte stream.
```rust
use std::convert::TryInto;
fn shift_hash(short_string: &[u8]) -> u64 {
fn xorlen64_hash(short_string: &[u8]) -> u64 {
let mut hash = 0;
let mut len = 0;
let mut chunks = short_string.chunks_exact(8);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment