gononono64

[Help] Quicksorting 2d Array by String Comparison Recusion Exceeded

9 posts in this topic

#1 ·  Posted

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

 

;;---------------------------------------------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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

#4 ·  Posted

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"

Share this post


Link to post
Share on other sites

#5 ·  Posted

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)

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by gononono64
1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by czardas
1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted

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 :D

Share this post


Link to post
Share on other sites

#9 ·  Posted

You're more than welcome.

1 person likes this

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
    • DagSa
      By DagSa
      Try to find a solution for help files to my autoit executable.
      Its installed from simple XP-POS cash computers to desktop with windows 7, 8, 10.
      The compiled AutoIt program itself work everywhere, but the help file??
      I need a help file called from from the program and I don't really know what working best in all OS platforms.
      1. A wordfile is helpful enough, but word is not installed everywhere.
      2. RTF is very big files with pictures.
      3. I could save it as pdf, but not all have it either.
      4. Tried  .MHT file, but downside is browser could cover hole screen if browser closed this way. I have not found any way to resize it to specific size when open up.
      5. Use of IE.au3 lib. Well it could open mht files ,but always got question about use it as default browser or not. Think this also make IE browser lose control so I could not resize.
      6. Look at making a  .CHM file, but I don't think its the future do use that format. (.hlp is no no and old)

      Any tips of do it in autoit or make a call to open up in some nice format working everywhere.
       
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • geekyworld
      By geekyworld
      Hi. I want to read the help file on my Kindle ebook reader (to protect my eyes). Is it available in Kindle or epub format? I tried converting it myself but the results were not very good.
      --Thanks!