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

Use a Set on primitive type unions to verify if they are valid #1054

Open
ImUrX opened this issue May 8, 2024 · 2 comments
Open

Use a Set on primitive type unions to verify if they are valid #1054

ImUrX opened this issue May 8, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Projects

Comments

@ImUrX
Copy link

ImUrX commented May 8, 2024

Feature Request

Imagine a type for example a type called Alpha3Code which contains an union of strings of all valid ISO 3166-1 alpha-3.

The validation currently would just generate a comparison check for each primitive by doing a lot of logical ORs like this:

"ABW" === input.country ||
"AFG" === input.country ||
"AGO" === input.country ||
"AIA" === input.country ||
"ALA" === input.country
// etc...

But typia could generate a Set based on all the types and simply do set.has(input.country) instead which would be much more optimized.

@samchon samchon self-assigned this May 9, 2024
@samchon samchon added the good first issue Good for newcomers label May 9, 2024
@samchon
Copy link
Owner

samchon commented May 9, 2024

It seems good idea, but needs entire level refactoring of compiler related codes.

This feature would be adjusted to the v7 major update, so please wait for some months.

By the way, if the number of constant literal values are lower, using Set<T> strategy becomes slower than current individual comparisons. Therefore, need to determine the standard number whether to use Set<T> strategy or not. About the count, do you have any idea? If not, I'll determine it after measuring a benchmark.

@samchon samchon added the enhancement New feature or request label May 9, 2024
@samchon samchon added this to To do in v7 Update May 9, 2024
@ImUrX
Copy link
Author

ImUrX commented May 9, 2024

If we are talking about same length text, I'm betting around 10, but yes a benchmark seems like a good idea specially for the other cases.

There is other optimizations that could be done depending on type, like strings could also have their min and max length taken for checking before looking them up and numbers could do the same by taking their min and max number which are all cheaper operations compared to a Set lookup but that should be another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Development

No branches or pull requests

2 participants