aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-09-29 09:56:15 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-09-29 10:01:27 +0200
commit42d05c8a3f59f99daccaf65a117d183828446d71 (patch)
treeaff35e0dc058164cb29810a2fc44366ef8d9d758
parentdbf2f4d6d117d8ef951224f07ccf62bb89d6ec6b (diff)
downloadmendeleev-42d05c8a3f59f99daccaf65a117d183828446d71.tar.gz
Test the longest tail
-rw-r--r--mendeleev.c9
-rw-r--r--mendeleev.f906
-rw-r--r--mendeleev.py8
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]