Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active March 29, 2018 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/0523c832c678df6a5e7128c812da0d3d to your computer and use it in GitHub Desktop.
Save kunigami/0523c832c678df6a5e7128c812da0d3d to your computer and use it in GitHub Desktop.
let m: u32 = 1 << b;
let mut first_non_zero_by_bucket: Vec<u32> = vec![0 as u32; m as usize];
for element in elements {
let hash_value = hash(&element);
// Extracts the first b bits from hash_value to determine the bucket
let bucket_index: usize = (hash_value & first_b_bits_mask) as usize;
// Finds the position of the first 1 bit in the remaining bits
let mut first_non_zero: u32 = first_non_zero_bit_position(hash_value >> b);
first_non_zero_by_bucket[bucket_index] = cmp::max(
first_non_zero_by_bucket[bucket_index],
first_non_zero
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment