Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Code completion with partial matching
dmoore:
@alpha: This untested pseudo code (which looks a bit like C/C++) is roughly what I had in mind:
--- Code: ---int find(const wxString &str, const wxString &substr)
{
int pos = str.Find(substr);
return pos == wxNOT_FOUND? str.Len() : pos;
}
wxString acronym(const wxString &str)
{
wxString s = str.Mid(0,1);
for (i=1;i<str.Len();++i)
{
n = str.Mid(i,1);
bool underscore = false;
while (n == _T("_"))
{
underscore=true;
++i;
n = str.Mid(i,1);
}
if (n==wxEmptyString)
break;
if (underscore || n == n.upper())
s<<n;
}
return s;
}
int min(int x, int y)
{
return x<y? x:y;
}
int score(const wxString &a,const wxString &value)
{
wxString al = a.Lower();
wxString aa = acronym(a);
wxString aal = aa.Lower();
int pos_a = find(a, value)*4;
int pos_al = find(al, value.Lower())*4+1;
int pos_aa = find(aa, value)*4+2;
int pos_aal = find(aal, value.Lower())*4+3;
return min(min(pos_a,pos_al),min(pos_aa,pos_aal));
}
--- End code ---
possible that your code does exactly the same thing, but I had trouble getting my head around the bit shifts. Would want to make sure the equal scored items are alphabetized as well.
Alpha:
I believe your pseudo code is fairly similar to what my code attempts. It is definitely a lot more readable than my code, so if I am able to get it to function similarly, I will try to use it to replace my current implementation.
Sorry about the bit shifts; I used them in CalcPrefixValue() so that the output score would be in the same range as CalcValue(). (Using shifts in CalcValue() was (sort of) necessary because it attempts to quantize different states, and each of which must have greater impact on the output, than the combination of all following tests.)
(I apparently got lost in the bit shifting in my code as well, because the CalcPrefixValue() I posted has a fairly bad overflow error. ... I will try to post a full patch later today containing the combination of ranking systems.)
Assuming the code is working how it is supposed to, alphabetization is already handled; items of equal weight are ordered by index, and the indices are pre-sorted to be alphabetical.
dmoore:
My pseudo code isn't completely right either. The "Find" calls that return wxNOT_FOUND should actually be ignored and not given a (albeit large) positive score.
Alpha:
Attached is the hybrid. To test without adaption, put a return at the beginning of CCManager::DoUpdateAdaption().
What do you think of the current performance? It *feels* acceptable to me right now (but I have not tested on multiple machines).
Alpha:
Another thought: the adaption mechanism can be made more deterministic running it in 'learning mode' for a session. Afterwards (in subsequent sessions), use the results as static data to run the heuristics.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version