From 42d05c8a3f59f99daccaf65a117d183828446d71 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Thu, 29 Sep 2022 09:56:15 +0200 Subject: Test the longest tail --- mendeleev.c | 9 ++------- mendeleev.f90 | 6 +----- mendeleev.py | 8 +------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/mendeleev.c b/mendeleev.c index 44e2cb4..81127dd 100644 --- a/mendeleev.c +++ b/mendeleev.c @@ -150,18 +150,13 @@ explode (const char *word) if (!formula) return NULL; - while (*word) + while (*formula->tail) { - word = NULL; formula_t *f = formula; while (f) { if (*f->tail) - { - advance (f); - if (!word) - word = f->tail; - } + advance (f); f = f->next; } } diff --git a/mendeleev.f90 b/mendeleev.f90 index c7df836..5abe2a4 100644 --- a/mendeleev.f90 +++ b/mendeleev.f90 @@ -171,23 +171,19 @@ contains character(len=*), intent(in) :: word type(formula_t), pointer :: formula - logical :: has_tail type(formula_t), pointer :: f allocate(formula) allocate(formula%elements(len(word))) - do + do while (formula%tail <= len(word)) f => formula - has_tail = .false. do while (associated(f)) if (f%tail <= len(word)) then call advance(word, f) - if (.not. has_tail) has_tail = f%tail <= len(word) end if f => f%next end do - if (.not. has_tail) exit end do end function explode end program mendeleev diff --git a/mendeleev.py b/mendeleev.py index a9615aa..21bc600 100644 --- a/mendeleev.py +++ b/mendeleev.py @@ -76,23 +76,17 @@ def advance(els, tail): def explode(word): result = [([], word.lower().encode())] - while True: + while result[0][1]: new = [] - tail = None for res in result: if res[1]: adv = advance(*res) new.extend(adv) - if not tail: - tail = adv[0][1] else: new.append(res) result = new - if not tail: - break - return [els for els, _ in result] -- cgit v1.2.3