How the hell does xlobby sort things (code string compare)?

Help each other out

How the hell does xlobby sort things (code string compare)?

Postby S Pittaway on Wed Oct 18, 2006 7:16 am

How the hell does xlobby sort things?

I wanted to speed up xJumpto....

If its a sorted category it should be easy, i can page forward or backwards untill i pass the item i am lokking for, then i can simple item back untill if find it or its not there....

So a few lines of code later and it all looks like its working...

Try it on my playlist a and it doesent work.


Steve seems to use some weird sort method -

this is the sorted order i get in xlobby, does anyone know what string compare function steve is using?

13
18
"all the"
#1
(the )
(what)
100% car
101
11
1980
1992
30
'74
a
b
c
etc[/b]
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Postby S Pittaway on Sat Oct 21, 2006 2:31 pm

Just in case anyonw else ever needs to know, this seems to work ok -



const int STR_CMP_LT = -1;
const int STR_CMP_GT = 1;
const int STR_CMP_EQ = 0;

static int StrCmp(string A, string B)
{
int Result;
if (A == null && B == null)
Result = 0;
else if (A == null)
Result = -1;
else if (B == null)
Result = 1;
else if (A.Equals(string.Empty) && B.Equals(string.Empty))
Result = 0;
else if (A.Equals(string.Empty))
Result = -1;
else if (B.Equals(string.Empty))
Result = -1;
else
{
bool sp1 = Char.IsLetter(A, 0);
bool sp2 = Char.IsLetter(B, 0);

//letters at the end
if (sp1 && !sp2)
Result = 1;
else if (!sp1 && sp2)
Result = -1;
else
{
double AVal;
double BVal;

sp1 = double.TryParse(A, out AVal);
sp2 = double.TryParse(B, out BVal);

//numbers at the start
if (sp1 && !sp2)
Result = -1;
else if (!sp1 && sp2)
Result = 1;
else if (sp1 && sp2)
{
if (AVal == BVal)
Result = STR_CMP_EQ;
else if (AVal < BVal)
Result = STR_CMP_LT;
else
Result = STR_CMP_GT;
}
else
{
Result = String.Compare(A, B, StringComparison.CurrentCultureIgnoreCase);
}
}
}

if (Result == 0)
return STR_CMP_EQ;
else if (Result < 0)
return STR_CMP_LT;
else
return STR_CMP_GT;
}
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England