Skip to content

Static assertion in switch statement is overly broad #4

@lorenzhs

Description

@lorenzhs

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");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions