Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/fga

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#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 */

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].