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

Needs find-longest key method #14

Open
KCzar opened this issue Oct 12, 2014 · 5 comments
Open

Needs find-longest key method #14

KCzar opened this issue Oct 12, 2014 · 5 comments

Comments

@KCzar
Copy link

KCzar commented Oct 12, 2014

Or we could just call it a "longest" method - or "prefix" method (singular). Is there an efficient way to find the longest key that is a prefix of a string that I'm overlooking? It could be done with the current implementation by simply using prefixes, then finding the longest match, but there should be a much more efficient way possible by taking advantage of the Trie properties.

I can give it a go if you like - unless it's already implemented and I'm simply missing it.

@stuaxo
Copy link

stuaxo commented Apr 28, 2016

Not sure if I want the same thing, but it sounds like it -

given

Trie([u'some.long.name', u'some.short.name'])
I'd like a way to get back

[u'some.long', u'some.short'])

@superbobry
Copy link
Member

I'm not sure if this is possible using the public API of marisa-trie the C++ library. Need to check and then maybe forward the issue upstream.

@KCzar
Copy link
Author

KCzar commented May 5, 2016

When I originally posted that, I for some reason didn't realize 'prefixes' returned them in order (duh), so what I needed was basically already implemented satisfactorily.

What you stuaxo want is something else. I'm not completely sure what you want though...

@stuaxo
Copy link

stuaxo commented May 5, 2016

In the end, I implemented this using a different library, + what I needed turned out to be slightly different - I needed something like this:

t = Trie([u'some.long.name', u'some.short.name'])
t.longest_unique_prefixes()
u['some.']
t = Trie([u'some.long.name', u'some.short.name', 'blah.1', 'blah.2'])
t.longest_unique_prefixes()
u['some.', 'blah.']

@stuaxo
Copy link

stuaxo commented May 5, 2016

^ I guess what I wanted needed here is the 'roots' of the Trie.

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

No branches or pull requests

4 participants