fst
fst copied to clipboard
find the last element in a `Stream`?
Would it be possible to make it fast to either reverse a Stream
or to find the last element in it? I just want to know the first and last element matching my query, and would like to do so without iterating through everything in between.
I think #129 is related? If you didn't know, the raw API let's you walk the automaton. I think it exposes every capability. So if you can't do it with that, then I don't think it's possible.
With that said, if you just want the maxkey, I think that can be done by traversing the last transition in each state? There is no specific API for it, but I think coding it up shouldn't be too bad?
Thanks for the rapid response! Maybe I can take a look tomorrow. I'll have to take a look at the lower level API. Do you think this could be added as a last
method in Stream
?
I don't have this crate paged into context at the moment and I probably won't have time to page it in soon.
My suspicion is that you cannot add last to a generic interface. But you might be able to add it to the automaton types themselves. You might be able to write a last method that accepts anything that imple Automaton though?
Don't take my word for gospel though.
Great, thanks!
Somewhat related but maybe distinct enough for its own issue, there's no way to iterate over fst::map::Values
or fst::set::Stream
in a reversed order, nor any way I can see to make Automation
do something like that (without allocating a vec and collecting all elements before iterating over that in a reversed order)