Hi, have a few questions about the sort natives and ArrayFindString native:
1. Recently I came across a problem with sorting an array that has a lot of equal items. After the sorting, the items are being "shifted" down for some reason and I don't know if it's supposed to be like this. Here's an example code:
for(new i = 0; i < 5; i++)
{
console_print(0, "%d | %d", i, array[i]);
}
}
public sort()
{
return 0; //items equal
}
Result:
Quote:
0 | 1
1 | 2
2 | 3
3 | 4
4 | 0
The result is the same when I tried it on SortCustom1D, ArraySort or ArraySortEx.
If all the items are equal (according to my sort algorithm), so why does the index change? shouldn't it stay the exact same?
Also -- on a side note, would be really cool to have a cmp(x,y) native/stock inside a default include file, just like floatcmp has one.
2. ArrayFindString checking contain instead of equal and is case sensitive. Basically this makes this native useless 90% of the the times, it's to dangerous to use it if it's acting like 'contain' (instead of 'equal') and it's not very practical. If I have an array of SteamIDS, I might get STEAM_0:111156 when searching for STEAM_0:1111. If I have an array of maps I might get de_dust2 when searching for de_dust. Would be very nice to have a parameter for case insensitive/case sensitive and maybe a param/second native if to act like 'contain' or 'equal'.
Thank you for keeping this project alive, everyone.
SortCustom1D(and other natives probably) uses qsort to perform the actual sorting. http://www.cplusplus.com/reference/cstdlib/qsort/
Documentation says the order of equal elements is undefined, this is why.
SortCustom1D(and other natives probably) uses qsort to perform the actual sorting. http://www.cplusplus.com/reference/cstdlib/qsort/
Documentation says the order of equal elements is undefined, this is why.
Thanks, that explains it.
So basically if i'll do 'return 1' for equal items it will work as I expected.
That's if I have an array of integers. This was just an example for the post. Lets say I have an array of SteamIDs + points to each key, if 2 SteamIDs have the same amount of points their index will still change.