Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash_128_above can only cover half string for hash compute #189

Open
wymhuster opened this issue Nov 26, 2022 · 1 comment
Open

hash_128_above can only cover half string for hash compute #189

wymhuster opened this issue Nov 26, 2022 · 1 comment

Comments

@wymhuster
Copy link

wymhuster commented Nov 26, 2022

static LJ_NOINLINE uint32_t hash_128_above(uint64_t seed, const char* str,
					   uint32_t len)
{
  uint32_t chunk_num, chunk_sz, chunk_sz_log2, i, pos1, pos2;
  uint64_t h1, h2, v;
  const char* chunk_ptr;

  chunk_num = 16;
  chunk_sz = len / chunk_num;
  chunk_sz_log2 = log2_floor(chunk_sz);

  pos1 = get_random_pos_unsafe(chunk_sz_log2, 0);
  pos2 = get_random_pos_unsafe(chunk_sz_log2, 1);

  h1 = lj_crc32_u32(0, len ^ seed);
  h2 = 0;

  /* loop over 14 chunks, 2 chunks at a time */
  for (i = 0, chunk_ptr = str; i < (chunk_num / 2 - 1);
       chunk_ptr += chunk_sz, i++) {

    v = *cast_uint64p(chunk_ptr + pos1);
    h1 = lj_crc32_u64(h1, v);

    v = *cast_uint64p(chunk_ptr + chunk_sz + pos2);
    h2 = lj_crc32_u64(h2, v);
  }

every loop just move one chunk,it's a bug here? the loop only cover half string
should we set chunk_ptr += 2*chunk_sz
#60

@wymhuster wymhuster changed the title hash_128_above can only cover half string hash_128_above can only cover half string for hash compute Nov 26, 2022
@wymhuster
Copy link
Author

@zhuizhuhaomeng @agentzh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant