crydev Messages: 151 Registered: October 2012 Location: Netherlands
Experienced Member
I searched all over the forum and documentation and I used Visual Studio intellisense to help me, but I just cannot understand how I should sort a Vector. The Vector in this case is a Vector<MovieInfo>, which is a struct I wrote myself.
I found the different Sort functions but I simply don't understand how they work. I am used to using predicates, delegates and operators using C# to sort arrays and find values in one.
The problem is that I am using a Vector of items with an ArrayCtrl containing those items. I sorted the ArrayCtrl, which makes the indices different from the Vector. To sort my ArrayCtrl I simply used:
ArrayCtrl.Sort();
Which sorted alphabetically. I need to have the same for my Vector.
Can you help me?
However, the two Sort methods do not have the same algorithm! I have tried to find out another way of fixing my problem but since I am using callbacks to fill up my ArrayCtrl one item by another from another thread I'm having trouble finding out how I could sort on the fly.
The ArrayCtrl.Sort() and Sort(myVector) both sort alphabetically, but not exactly the same. What should I do to abandon this problem? Is there a way maybe to sort on the fly so I can keep my callback system?
crydev Messages: 151 Registered: October 2012 Location: Netherlands
Experienced Member
koldo wrote on Mon, 19 November 2012 09:02
Hello Crydev
What is the best way for you, the ArrayCtrl system or the Sort system?
Hi Koldo,
The Sort(myVector) system is the best way for me. I noticed that this method has a better way of handling differences in string lengths and also in strings that contain numbers.
AFAIK ArrayCtrl Sort() uses Value comparison that in case of Strings uses DefaultLanguageCompare() function in LangInfo.cpp. However String comparison uses String0::Compare() in AString.hpp.
If you prefer the second, I suppose that you have to create a comparison function like this;
int MyStringCompare(const Value& a, const Value& b) {
return a.ToString() < b.ToString();
}
crydev Messages: 151 Registered: October 2012 Location: Netherlands
Experienced Member
koldo wrote on Mon, 19 November 2012 16:09
Hello Crydev
AFAIK ArrayCtrl Sort() uses Value comparison that in case of Strings uses DefaultLanguageCompare() function in LangInfo.cpp. However String comparison uses String0::Compare() in AString.hpp.
If you prefer the second, I suppose that you have to create a comparison function like this;
int MyStringCompare(const Value& a, const Value& b) {
return a.ToString() < b.ToString();
}
and refer to it in Sort:
array.Sort(columnToSort, MyStringCompare);
I have not tested it. Does it work?
I tested this. It did work by meaning of: it works, but it didn't work by meaning of it did what I was expecting.
You are saying that the sorting of strings in the ArrayCtrl is done by using the default language rules for strings and the sorting of a vector by using the operator you provided is done by using standard english rules. Am I correct? If so, I think I would need the language specific way of sorting for my vector.