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

    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • StudioMaker
      By StudioMaker
      Hey anyone knows how i can have a inputbox that is connected to an HotKeySet? Like if u put in like "a" in the inputbox it sets the hotkey to "a"?
       
    • RyukShini
      By RyukShini
      I was wondering if its possible to make anything like this in AutoIT

       
      function toArr(str) { var ret = Array((str.length + 3) >> 2); // String to array of 32 bit ints for (var i = 0; i < str.length; i += 4) { // FYI: // NaN << x === 0 // x | NaN === x ret[i >> 2] = (str.charCodeAt(i ) << 24) | (str.charCodeAt(i+1) << 16) | (str.charCodeAt(i+2) << 8) | str.charCodeAt(i+3); } return ret; } function megaKdf(pw) { var pwkey = [0x93c467e3, 0x7db0c7a4, 0xd1be3f81, 0x0152cb56]; var arrPw = toArr(pw); var aes = Array((arrPw + 3) >> 2); // Init aes keys for (var i = 0; i < arrPw.length; i += 4) { aes[i >> 2] = new sjcl.cipher.aes([arrPw[i]|0, arrPw[i+1]|0, arrPw[i+2]|0, arrPw[i+3]|0]); } // Generate password key for (var i = 0; i < 65536; i++) { for (var j = 0; j < aes.length; j++) { pwkey = aes[j].encrypt(pwkey); } } return pwkey; } function loginHash(pwKey, email) { var aes = new sjcl.cipher.aes(pwKey); var arrEmail = toArr(email); var hash = [0, 0, 0, 0]; // Compress email with xor for (var i = 0; i < arrEmail.length; i++) { hash[i & 3] ^= arrEmail[i]; } // Generate hash for (var i = 0; i < 16384; i++) { hash = aes.encrypt(hash); } return sjcl.codec.base64.fromBits([hash[0], hash[2]], true, true); } function badRand32() { return Math.floor(0x100000000 * Math.random()); } function generateMasterKey() { return [badRand32(), badRand32(), badRand32(), badRand32()]; } function confirmationLinkHash(pwKey) { var aes = new sjcl.cipher.aes(pwKey); return aes.encrypt([badRand32(), 0, 0, badRand32()]); } function updateHashes(email, pw) { var pwKey = megaKdf(pw); var masterKey = generateMasterKey(); var clHash = confirmationLinkHash(pwKey, masterKey); var lHash = loginHash(pwKey, email); var aes = new sjcl.cipher.aes(pwKey); return lHash; } function htmlentities(str) { return str.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;"); } function analyzeLink(link, pw) { var linkHex = "N/A"; var masterKey = "N/A"; var encMasterKey = "N/A"; var pwHash = "N/A"; var unknown = "N/A"; var email = "N/A"; var spacer = "N/A"; var name = "N/A"; var unknown2 = "N/A"; if (link.substr(0, 27) == "https://mega.co.nz/#confirm") { link = link.substr(27); } if (link.substr(0, 19) == "mega.co.nz/#confirm") { link = link.substr(19); } if (link.substr(0, 8) == "#confirm") { link = link.substr(8); } if (link.search(/^[0-9A-Za-z\-_]*$/) == 0) { link = sjcl.codec.hex.fromBits(sjcl.codec.base64.toBits(link, true)); var pos; for (pos = 94; pos < link.length; pos += 2) { if (link.substr(pos, 2) == "09") { break; } } if (pos < link.length) { var pwKey = megaKdf(pw); var aes = new sjcl.cipher.aes(pwKey); var linkHash = aes.decrypt(sjcl.codec.hex.toBits(link.substr(32, 32))); if (linkHash[1] == 0 && linkHash[2] == 0) { masterKey = (new sjcl.cipher.aes(pwKey)).decrypt(sjcl.codec.hex.toBits(link.substr(0, 32))); masterKey = 'Base64: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.base64.fromBits(masterKey, true, true) + '</span> (hex: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.hex.fromBits(masterKey) + '</span>)'; } else if (pw != "") { masterKey = "Wrong password"; } encMasterKey = '<span style="color:#f00; font-family:monospace;">' + link.substr( 0, 32) + '</span>'; pwHash = '<span style="color:#080; font-family:monospace;">' + link.substr(32, 32) + '</span>'; unknown = '<span style="color:#00f; font-family:monospace;">' + link.substr(64, 30) + '</span>'; email = link.substr(94, pos - 94); spacer = '<span style="color:#0cc; font-family:monospace;">09</span>'; name = link.substr(pos + 2, link.length - 16 - pos - 2); unknown2 = '<span style="color:#000; font-family:monospace;">' + link.substr(link.length - 16) + '</span>'; linkHex = '<span style="font-family:monospace;">' + encMasterKey + " " + pwHash + " " + unknown + ' <span style="color:#888; font-family:monospace;">' + email + '</span> ' + spacer + ' <span style="color:#f0f; font-family:monospace;">' + name + '</span> ' + unknown2 + '</span>'; email = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(email))) + ' (<span style="color:#888; font-family:monospace;">' + email + '</span>)'; name = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(name))) + ' (<span style="color:#f0f; font-family:monospace;">' + name + '</span>)'; } } ge("linkHex").innerHTML = linkHex; ge("linkMasterKey").innerHTML = masterKey; ge("linkEncMasterKey").innerHTML = encMasterKey; ge("linkPwHash").innerHTML = pwHash; ge("linkUnknown").innerHTML = unknown; ge("linkEmail").innerHTML = email; ge("linkSpacer").innerHTML = spacer; ge("linkName").innerHTML = name; ge("linkUnknown2").innerHTML = unknown2; }  
    • barkeeper
      By barkeeper
      Hi there, not sure if this is the right place, but I'm building a script for using premade answers in chat. It works and outputs the answers (stored in an ini file based on:  answer name = answer it also works with a new line if there is a tag <enter> in the answer text in the ini file. Now the problem is, that after the answer is pasted in the chat (you bring up the interface with ctrl+1) it gives an enter, thus sending the output straight away. I would like to be able to review the answer before sending it. can anyone help me by telling what's wrong in the script, I tried replacing the @crlf in the script with other options, no luck. Thanks in advance! 
      antwoorden.au3
      antwoorden.ini
    • Mungo
      By Mungo
      After an update installation to Win 10 V.1607 (64bit) I have noticed that help does not show formatted properly anymore e.g. with Images missing, tables, headers, sample code mal formatted etc.

      However, if AutoIt3Help.exe is run as Administrator everything works fine.

      I have already uninstalled AutoIt and SciTE for AutoIt and reinstalled both in the latest version.  I have used default locations for the installation under:


      C:\Program Files (x86)\AutoIt3\...
      Any idea?

      Thanks