Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
--------------- --------- --------- --------- ---------
/mob/verb/Test 238.469 238.469 238.469 1
/mob/verb/Test2 17.469 17.469 17.469 1
I profiled the Test verb which sorted 100,000 elements of an associative list.
Test2 verb, creates the associative list with 100,000 elements.
Here goes :
var/list/List= list()
mob/verb/Test()
var/list/ValueList= list()
var/list/KeyList=list()
for(var/A in List)
KeyList += A
ValueList += List[A]
List=list()
for(var/A=1 to ValueList.len)
var/Value = max(ValueList)
var/index = ValueList.Find(Value)
var/Key = KeyList[index]
ValueList -= Value
KeyList -= Key
List[Key] = Value
mob/verb/Test2()
for(var/I = 1 to 100000)
var/Value = rand(1,200000)
var/rand2 = ascii2text(rand(1,255))
var/rand3 = ascii2text(rand(1,255))
var/rand4 = ascii2text(rand(1,255))
var/rand5 = ascii2text(rand(1,255))
var/Key = rand2+rand3+rand4+rand5
List[Key] = Value
Don't mind Test2() I just made it in a hurry to test my algorithm, anyways, I need help improving my algorithm, if possible. And thanks !
Regardless, I'm pretty sure changing the position of the key won't affect which key is mapped to which value, so you can just run any sorting algorithm over the list (DM can do > and < comparisons on strings). Just quicksort it.