gononono64 Posted March 3, 2017 Share Posted March 3, 2017 Hey there, I'm having some issues quick-sorting my 2d array imported from a database. Im trying to sort the array based on the name that would be returned in $array[$n][2]. The code i posted works for smaller arrays but for some reason when i try to sort my imported array (around 9000 indexes), I get "Recursion level has been exceeded". I understand that this is maybe due to lack of returns but i couldn't find an ideal spot to stick em and again it seems to work with smaller bits of code. Could it be that 9000 is too much? I would normally just trial and error it until i figured it out but due to the length of time to load and buffer my array it's become too time consuming. Really I'm just hoping there is a quick fix that someone with more experience happens to know. Thank you expandcollapse popup;;---------------------------------------------This Works---------------------------------------------------- Local $a[7][2] = [ _ ["1", "asdfashks"], _ ["2", "SubStrlkghjing1"], _ ["3", "jdfghjsergh"], _ ["4", "nertynert"], _ ["5", "cvbncvjkrt"], _ ["6", "avbncvjkrt"], _ ["7", "oytuoyuop"]] Quicksort($a,1,0,6) _ArrayDisplay($a) ;;------------------------------------------This Does Not--------------------------------------------------------- Quicksort($aLargeData, 1, 0, Ubound($aLargeData) - 1) _ArrayDisplay($aLargeData) ;;----------------------------------------Quicksort Function------------------------------------------------------ Func Quicksort(ByRef $Array, $secondIndex, $First, $Last) Local $pivot, $i, $j, $temp If $First < $Last Then $pivot = $First $i = $First $j = $Last While ($i < $j) While (StringCompare($Array[$i][$secondIndex], $Array[$pivot][$secondIndex]) <= 0) And ($i < $Last) $i += 1 WEnd While (StringCompare($Array[$j][$secondIndex], $Array[$pivot][$secondIndex]) > 0) $j -= 1 WEnd If ($i < $j) Then _ArraySwap($Array, $i, $j) _ArraySwap($Array,$pivot,$j) Quicksort($Array, $secondIndex, $First,$j-1) Quicksort($Array, $secondIndex, $j+1,$Last) WEnd EndIf EndFunc Link to comment Share on other sites More sharing options...
spudw2k Posted March 3, 2017 Share Posted March 3, 2017 I believe functions will return 0 at the conclusion of the function if a return isn't specified, though I can't remember where I read/learned that. Give this a read if you haven't already.https://www.autoitscript.com/wiki/Recursion#A_way_of_avoiding_of_recursion Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
jchd Posted March 3, 2017 Share Posted March 3, 2017 Sideways question: can't you just use an order by clause when exporting data from the DB engine? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
gononono64 Posted March 3, 2017 Author Share Posted March 3, 2017 I need to be able to sort the array in multiple ways after it is buffered. otherwise it would take an eternity to search in the "app" Link to comment Share on other sites More sharing options...
czardas Posted March 4, 2017 Share Posted March 4, 2017 What happens if you use _ArraySort() instead of the QuickSort() function you posted? Using the same array, could you tell me if the following also produces a recursion error? - Thanks. (ArrayWorkshop.au3 can be found in my signature) #include 'ArrayWorkshop.au3' Local $aArray ; replace with your array _ArraySortXD($aArray, Default, Default, Default, 0, 1) operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
gononono64 Posted March 4, 2017 Author Share Posted March 4, 2017 (edited) 1 hour ago, czardas said: What happens if you use _ArraySort() instead of the QuickSort() function you posted? Using the same array, could you tell me if the following also produces a recursion error? - Thanks. (ArrayWorkshop.au3 can be found in my signature) #include 'ArrayWorkshop.au3' Local $aArray ; replace with your array _ArraySortXD($aArray, Default, Default, Default, 0, 1) Yay it works!!! Thank you so much. Would u mind if i used the functions from ur file? Edited March 4, 2017 by gononono64 czardas 1 Link to comment Share on other sites More sharing options...
czardas Posted March 4, 2017 Share Posted March 4, 2017 (edited) Thanks for the report. We now know that there is a flaw in the logic in the QuickSort() function you posted (probably a comparison failure). Of course you can use my functions. If you need any help with them, let me know. Did you test the standard _ArraySort() function? Edited March 4, 2017 by czardas gononono64 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
gononono64 Posted March 4, 2017 Author Share Posted March 4, 2017 18 minutes ago, czardas said: Thanks for the report. We now know that there is a flaw in the logic in the QuickSort() function you posted (probably a comparison failure). Of course you can use my functions. If you need any help with them, let me know. Did you test the standard _ArraySort() function? Yes it didnt suit my needs. Thank you and much appreciated Link to comment Share on other sites More sharing options...
czardas Posted March 4, 2017 Share Posted March 4, 2017 You're more than welcome. gononono64 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now