refactor: share the lookup loop of `DiscrTree.getMatch` and `Sym.getMatch`

`DiscrTree.Trie.getMatchLoop` traverses a trie for the subterms of a query, parametrized over computing the key of a subterm and pushing its arguments, and replaces the two copies of this loop. `Trie.matchesSuffix` takes the same two functions, so arguments are only pushed when their key matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed