in h3_h3Index.c [263:300]
int H3_EXPORT(isValidCell)(H3Index h) {
/*
Look for bit patterns that would disqualify an H3Index from
being valid. If identified, exit early.
For reference the H3 index bit layout:
| Region | # bits |
|------------|--------|
| High | 1 |
| Mode | 4 |
| Reserved | 3 |
| Resolution | 4 |
| Base Cell | 7 |
| Digit 1 | 3 |
| Digit 2 | 3 |
| ... | ... |
| Digit 15 | 3 |
Speed benefits come from using bit manipulation instead of loops,
whenever possible.
*/
if (!_hasGoodTopBits(h)) return false;
// No need to check resolution; any 4 bits give a valid resolution.
const int res = H3_GET_RESOLUTION(h);
// Get base cell number and check that it is valid.
const int bc = H3_GET_BASE_CELL(h);
if (bc >= NUM_BASE_CELLS) return false;
if (_hasAny7UptoRes(h, res)) return false;
if (!_hasAll7AfterRes(h, res)) return false;
if (_hasDeletedSubsequence(h, bc)) return false;
// If no disqualifications were identified, the index is a valid H3 cell.
return true;
}