Hi Bram, On Sun, Sep 13, 2020 at 3:44 AM Bram Moolenaar <b...@moolenaar.net> wrote:
> > > >> On Sat, Sep 12, 2020 at 1:09 PM Prabir Shrestha < > > >> vim-dev-git...@256bit.org> wrote: > > >> > > >>> +1 for adding fuzzy match. > > >>> > > >>> A bit late to this. But few questions. > > >>> > > >>> How do we use matchfuzzy for a list of dictionary instead of item. > > >>> Primary reason for this is LSP (language server protocol) makes > heavy use > > >>> of user_data. Can you add an example for sorting a list whose type > is dict [ > > >>> { 'word': 'foo', user_data: 1}, { 'word': 'foobar', user_data: 2}, { > > >>> 'word': 'bar', user_data: 3} ]. Should we have a 3rd optional > parameter > > >>> that takes a callback? > > >>> > > >>> let completeitems = [ > > >>> \ { 'word': 'foo', user_data: 1}, > > >>> \ { 'word': 'foobar', user_data: 2}, > > >>> \ { 'word': 'bar', user_data: 3} > > >>> \ ] > > >>> let filtertedlist = matchfuzzy(completeitems, 'foo', > {item->item['word']}) > > >>> > > >>> > > >> That is a good idea. We can add a callback argument that will be > called > > >> for each item > > >> if the list item is dictionary. > > >> > > > > > > You can try the attached diff which implements the above and see how > this > > > works with a > > > very large list of dictionaries. > > > > > > > > I used the below functions to measure the time it takes to fuzzy search a > > million entries > > in a List and a Dict: > > > > > > For a list, it took around a second to search all the entries and for a > > dict, > > it took around 5.5 seconds. > > A list is always going to be more efficient than a dict. It uses less > memory and doesn't require hashing for the lookup. > > Also, when using a dict the key will be the same and rather meaningless? > The key is used to lookup the value in the dict which will be used for fuzzy matching. So the value will be different for each list item. > I can only imagine this being useful if you already have a list of > dicts. How often does that happen? > > For example, the getbufinfo(), gettagstack(), readdirex(), getqflist(), getloclist(), getmatches() and getwininfo() functions return a list of Dicts. Without the support for fuzzy searching list of Dicts, the user needs to first convert it to a List (while still retaining the rest of the information in the Dict) and then search. For example, to fuzzy search 'eval' in a list of buffers returned by getbufinfo(): With the support for fuzzy searching a list of Dicts using a 'key': echo getbufinfo()->matchfuzzy('eval', 'name') Generating a list of buffer names and then search (but the other buffer related information is not kept): echo getbufinfo()->map({_, v -> v.name})->matchfuzzy('quickfix.c') Generating a list of lists with two elements and then searching using the first element: echo getbufinfo()->map({_, v -> [v.name, v]})->matchfuzzy('quickfix') The first approach is more natural. In the last approach, the user needs to generate a temporary list of lists for fuzzy search. Regards, Yegappan > Using a list of lists, where the inner list has the text to fuzzy-match > on as the first item and the rest of the list can be anything, would be > the most efficient. Looking up the first item of a list is fast as > well. Only creating this list of lists might take extra time, if you > have an already existing structure. > > [['abcd', oneData], ['bcde', twoDta]]->matchfuzzy('cd') > > > -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/CAAW7x7nbeAhUpG7_UUvVf0Z1YBAFx3COv3ZgnckMATaXZY584w%40mail.gmail.com.