Skip to content

Look up sparse enum identifiers in a hash table instead of a linear search - #4899

Open
avikivity wants to merge 1 commit into
fmtlib:mainfrom
avikivity:enum-hash
Open

Look up sparse enum identifiers in a hash table instead of a linear search#4899
avikivity wants to merge 1 commit into
fmtlib:mainfrom
avikivity:enum-hash

Conversation

@avikivity

Copy link
Copy Markdown
Contributor

Enums that are too sparse for the index table were formatted by scanning all enumerators. Replace the scan with an open-addressed hash table with linear probing, sized to the smallest power of two that keeps the load factor at or below 0.5. This guarantees a free slot, which terminates the probe sequence and doubles as the not-found result because identifiers are never empty.

…earch

Enums that are too sparse for the index table were formatted by scanning
all enumerators. Replace the scan with an open-addressed hash table with
linear probing, sized to the smallest power of two that keeps the load
factor at or below 0.5. This guarantees a free slot, which terminates the
probe sequence and doubles as the not-found result because identifiers
are never empty.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@avikivity
avikivity requested a review from vitaut as a code owner August 25, 2026 09:22
@avikivity

Copy link
Copy Markdown
Contributor Author

Note: https://github.com/Kronuz/constexpr-phf exists, but I consider it overkill for this purpose.

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

Successfully merging this pull request may close these issues.

1 participant