Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find the last element in a Stream? #144

Open
droundy opened this issue Jul 30, 2022 · 5 comments
Open

find the last element in a Stream? #144

droundy opened this issue Jul 30, 2022 · 5 comments

Comments

@droundy
Copy link

droundy commented Jul 30, 2022

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.

@BurntSushi
Copy link
Owner

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?

@droundy
Copy link
Author

droundy commented Jul 30, 2022

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?

@BurntSushi
Copy link
Owner

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.

@droundy
Copy link
Author

droundy commented Jul 30, 2022

Great, thanks!

@Kixiron
Copy link

Kixiron commented Apr 30, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants