Add a "prefix" search for non-scope autocompletion
commitad77ee15dac78d3cc2a01e16828dfbcad33fa2d3
authorJiří Techet <techet@gmail.com>
Fri, 15 Jan 2016 14:46:00 +0000 (15 15:46 +0100)
committerJiří Techet <techet@gmail.com>
Mon, 18 Jan 2016 21:56:10 +0000 (18 22:56 +0100)
treebce20710813710f91b54bfb8df243d37e6973224
parent5b4c6f96b20cd309026e42c02133b28d1e0e64df
Add a "prefix" search for non-scope autocompletion

The main reason for separating m_workspace_find() into two parts is the
fact that when matching only the prefix, the result may contain too
many results and we need to go through all of them, return them and at the
end discard most of them.

For instance, when considering the linux kernel project with 2300000 tags
and when autocompletion is set to be invoked after typing a single character,
we get on average something like 100000 results (tag_num/alphabet_size).
But from these 100000 results, we get only the first 30 which we display
in the popup and discard the rest which means going through the list of
the 100000 tags and comparing them for no reason.

Thanks to using binary search for the start and the end of the sequence of
matching tags (added in a separate patch), we can get the start of the
sequence and the length of the sequence very quickly without going through
it.

For the prefix search we can limit the number of tags we are interested
in and go through at most this number of returned tags (to be precise,
times two, because we need to go both through the workspace array and
global tags array and remove the extras only after sorting the two).

It would be possible to combine both tm_workspace_find() and
tm_workspace_find_prefix() into a single function but the result is a bit
hard to read because some of the logic is used only in tm_workspace_find()
and some only in tm_workspace_find_prefix() so even though there is some
code duplication, I believe it's easier to understand this way.
src/editor.c
tagmanager/src/tm_workspace.c
tagmanager/src/tm_workspace.h