// Package graph provides thin, reusable helpers over a dafsa Cursor that the move // generator builds on. It keeps the rest of the solver from depending on dafsa // traversal details directly. package graph import dawg "github.com/iliadenisov/dafsa" // Spell follows the given alphabet indices from the cursor's root. It returns the // state reached, whether that state is accepting, and whether the whole path exists. // When ok is false the path ran into a missing edge; n and final are meaningless. func Spell(c *dawg.Cursor, indices []byte) (n dawg.Node, final, ok bool) { n = c.Root() final = c.Final(n) for _, ix := range indices { n, final, ok = c.Next(n, ix) if !ok { return n, false, false } } return n, final, true }