improve term count prediction

This commit is contained in:
hugogogo
2026-05-01 02:11:12 +02:00
parent 241cbdaff1
commit 2eeed8580f
2 changed files with 48 additions and 28 deletions

View File

@@ -23,10 +23,24 @@ void remove_spaces(char *s)
}
}
int count_any_of(const char *s, const char *set)
{
int count = 0;
for (; *s != '\0'; s++)
{
if (ft_strchr(set, *s) != NULL)
{
count++;
}
}
return count;
}
int main(int ac, char **av)
{
int i;
int arg_len;
int terms_count_prediction;
char *input;
if (ac < 2)
@@ -59,11 +73,11 @@ int main(int ac, char **av)
ft_putchar('\n'); // debug
token tokens[arg_len];
int token_count = lexerize(input, tokens);
int tokens_count = lexerize(input, tokens);
ft_putstr("-> token_count : "); // debug
ft_putnbr(token_count); // debug
ft_putchar('\n'); // debug
ft_putstr("-> tokens_count : "); // debug
ft_putnbr(tokens_count); // debug
ft_putchar('\n'); // debug
// tmp debug output
ft_putchar('\n'); // debug
@@ -108,12 +122,18 @@ int main(int ac, char **av)
ft_putchar('\n'); // debug
// END tmp debug output
term terms[token_count / 2];
terms_count_prediction = count_any_of(input, "-+=") + 1; // +1 for first term that can have no leading '+'
ft_putstr("-> terms_count_prediction : "); // debug
ft_putnbr(terms_count_prediction); // debug
ft_putchar('\n'); // debug
term terms[terms_count_prediction];
int term_count = parse(tokens, terms);
ft_putstr("-> term_count : "); // debug
ft_putnbr(term_count); // debug
ft_putchar('\n'); // debug
ft_putstr("-> terms_count : "); // debug
ft_putnbr(term_count); // debug
ft_putchar('\n'); // debug
return (0);
}