#include <stdio.h>
#include <libc.h>
int nstate;
static void enter(register char *a, int code)
{
register int state = 0, s;
for (; (s = g(state, *a)) != FAIL; state = s, a++)
;
for (; *a; a++) {
setg(state, *a, nstate);
state = nstate++;
}
setoutput(state, nstate, code);
}
/*
nstate = 0
for i=1 to k { enter(words[k], code[k]) }
for all a: g(0,a)=fail { set g(0,a)=0 }
*/
/*
queue = empty;
for each a: g(0,a)=s && s != 0 { // states depth 1
queue = queue + {s}
f(s) = 0
}
while queue != empty {
r = head(queue)
queue = queue - {r}
for each a: g(r,a)=s, s!=fail { // states depth d from d-1
queue = queue + {s}
state = f(r)
while g(state,a)=fail
state = f(state)
f(s) = g(state,a)
output(s) = output(s) + output(f(s))
}
}
*/
/* can collapse failure functions */
|