Hi, On Sat, Sep 12, 2020 at 3:54 PM Yegappan Lakshmanan <[email protected]> wrote:
> >> On Sat, Sep 12, 2020 at 1:09 PM Prabir Shrestha < >> [email protected]> 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: ========================================== func MeasureList() let l = ['abcdef']->repeat(1000000) let start = reltime() let m = l->matchfuzzy('bcd') let secs = start->reltime()->reltimefloat() echomsg "Elapsed Seconds = " .. secs->string() endfunc func MeasureDict() let l = [] for i in range(1, 1000000) call add(l, {'text' : 'abcdef', 'idx' : i}) endfor let start = reltime() let m = l->matchfuzzy('bcd', {v -> v.text}) let secs = start->reltime()->reltimefloat() echomsg "Elapsed Seconds = " .. secs->string() endfunc ========================================== For a list, it took around a second to search all the entries and for a dict, it took around 5.5 seconds. - Yegappan -- -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/CAAW7x7k61BU7Jfw19Fd9m4y629rUN82O9b8G8j_wZYhEE%3D4L1Q%40mail.gmail.com.
