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

Static assertion in switch statement is overly broad #4

Open
lorenzhs opened this issue Jun 24, 2021 · 0 comments
Open

Static assertion in switch statement is overly broad #4

lorenzhs opened this issue Jun 24, 2021 · 0 comments

Comments

@lorenzhs
Copy link

The following static assertion triggers even when it shouldn't because it is evaluated even when the alternate bucket selection method isn't TABLE_BASED_OFFSET, causing Morton1_8 to fail to compile (it uses FUNCTION_BASED_OFFSET, and the assertion shouldn't trigger).

static_assert(offsets[0] > _buckets_per_block,
"Cannot use TABLE_BASED_OFFSET with so many buckets per block");

context:

switch(_alternate_bucket_selection_method){
case AlternateBucketSelectionMethodEnum::TABLE_BASED_OFFSET:{
constexpr int16_t offsets[] = {83, 149, 211, 277, 337, 397, 457, 521,
587, 653, 719, 787, 853, 919, 983, 1051, 1117, 1181, 1249, 1319, 1399,
1459,
1511, 1571, 1637, 1699, 1759, 1823, 1889, 1951, 2017, 1579};//, 1579
static_assert(offsets[0] > _buckets_per_block,
"Cannot use TABLE_BASED_OFFSET with so many buckets per block");
offset = offsets[fingerprint % (sizeof(offsets) / sizeof(offsets[0]))];
break;
}
case AlternateBucketSelectionMethodEnum::FUNCTION_BASED_OFFSET:{
offset = ((raw_primary_hash(fingerprint) & 0x1fff) +
(_buckets_per_block)) | one;
break;
}
case AlternateBucketSelectionMethodEnum::FAN_ET_AL_PARTIAL_KEY:
return fan_et_al_partial_key_cuckoo_hash_alternate_bucket(bucket_id,
fingerprint);
break;
}

Since _alternate_bucket_selection_method is known at compile time, the inverse of the case taken should be added to the assertion, something like this:

static_assert(offsets[0] > _buckets_per_block ||
              _alternate_bucket_selection_method != AlternateBucketSelectionMethodEnum::TABLE_BASED_OFFSET,
  "Cannot use TABLE_BASED_OFFSET with so many buckets per block");
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