Jump to content

_ArraySearch


FuryCell
 Share

  

30 members have voted

  1. 1. Does this functionality seem useful?

    • Yes
      25
    • No
      2
    • Maybe
      3


Recommended Posts

A while ago I coded _ArraySearch. I often find it quite useful. Nonetheless there is one limitation that always bugged me. It didn't support multidimensional arrays. I have some code that adds support for multidimensional arrays. However it is still very much in development. The code I have now is attached below. (along with some examples.)

I am wondering if people would be interested in this kind of functionality.

ArraySearchAnyDim.zip

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Couple thoughts:

1. Right now it returns as soon as something is found, perhaps it should continue checking? Basically, what should it do if there are multiple entries of the same thing?

2. It would be pretty sweet for it to return both indeces when searching as well, otherwise the search has to be performed twice.

These *may* be out of scope, thought i'd ask though and see what you thought.

Link to comment
Share on other sites

Couple thoughts:

1. Right now it returns as soon as something is found, perhaps it should continue checking? Basically, what should it do if there are multiple entries of the same thing?

2. It would be pretty sweet for it to return both indeces when searching as well, otherwise the search has to be performed twice.

These *may* be out of scope, thought i'd ask though and see what you thought.

@stampy & @fisofo

Thanks for the replies

@fisofo

Sounds like an interesting idea.Maybe I will implement it after i finish debugging the multidimensional array support.

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

I say maybe useful in certain circumstances. I can see the ability for it to be used, but fail to see mass use. I'm sure most AutoIt users will find a use for it at least once in their scripts, but not very often.

Thanks for the reply. I usually use single dim arrays but a script i have been working on requires me to work with mulitdim arrrays hence my modification of _ArraySearch. :whistle:

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

  • 1 month later...

@SolidSnake

I was planning to write some array searching code for a task that I am working on at present and came across your post by luck while browsing through the Example Scripts, hopefully I'll be able to use your code instead, will certainly have a close look.

Either way I think array functions like this are alway going to be useful, computers are good at working with data so that means there always going to be people writing code to sort/search data. May not be every user, but the need will always be there.

VW

Link to comment
Share on other sites

Hi,

I am confused; the examples are only using 2D arrays . Does it really work for any number of dimensions, or only 1 or 2D?

best, randall

Should work with any array. :P

Dim $Array[3][2][2]

$Array[0][1][1] = 1
$Array[1][1][1] = 2
$Array[2][1][1] = 3

$Result = _ArraySearchAnyDim ($Array, "2", 0, 0, 0, "[x][1][1]") ;_ArraySearchAnyDim should return 1
ConsoleWrite($Result & "|" & @error & @LF)
Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

@SolidSnake

I was planning to write some array searching code for a task that I am working on at present and came across your post by luck while browsing through the Example Scripts, hopefully I'll be able to use your code instead, will certainly have a close look.

Either way I think array functions like this are alway going to be useful, computers are good at working with data so that means there always going to be people writing code to sort/search data. May not be every user, but the need will always be there.

VW

Thanks for the feedback. :P

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

  • 2 months later...

I just started working on a script that needs a multi-dimensional array search. I'm glad I found yours before I started writing one. I'll be testing it to death, and will let you know if I find anything.

Thanks! :whistle:

NP. :) Glad you have a use for it. If you are looking for even more features then check out _ArraySearchPlus()

This function combines the features of two different versions of _ArraySearch().

TheGuy0000's _ArraySearch()

SolidSnake's _ArraySearchAnyDim()

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

NP. :whistle: Glad you have a use for it. If you are looking for even more features then check out _ArraySearchPlus()

I saw that - those extra search features haven't hit any of my needs yet, but I was thinking....

What if I added a binary search to all of that (ArraySearch++? :)) So far, I've been able to get enough performance out of my script by not doing redims and other tweaks, but I am doing a bunch of searching in multi-dimensional arrays, so it would probably pay to sort it and then binsearch it. Has anyone else started on this, or should I go for it?

Link to comment
Share on other sites

I saw that - those extra search features haven't hit any of my needs yet, but I was thinking....

What if I added a binary search to all of that (ArraySearch++? :)) So far, I've been able to get enough performance out of my script by not doing redims and other tweaks, but I am doing a bunch of searching in multi-dimensional arrays, so it would probably pay to sort it and then binsearch it. Has anyone else started on this, or should I go for it?

I think it would be awesome if you extended the function. I'm sure many would find it useful to have a more robust binary search. I think it would be best if you called it ArrayBinarySearchPlus(). Good luck. :whistle:

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

  • 10 months later...

And the function is done. Took a bit of time.

#cs
up to 4 dimensions
$avArray is the input array
$sFind is a string of what to find
$sDimension is a string representing where to look
    "[-1][3]" will search all the entire first dimension and only the third subset of the second dimension
    "[3,5][-1][3]" will search the 3rd through 5th of d1, all of d2, and the 3rd of d3
$bAll, if true, returns all values in a two-dimensional array with array[0][0] being the number of values
    [1][0] will be first dimension's index, [1][2] will be third dimension's index
    [2][0] will be second answer's first dimension's index
$bAll, if false, will return a single-dimensional array with
    [0] being d1's index
    [3] being d4's index
$iCaseSensative - see StringCompare Help
#ce

Func _ArraySearchMultiDim($avArray, $sFind, $sDimension, $bAll = True, $iCaseSensative = 0)
    Local $w, $x, $y, $z
    Local $dimensions = UBound($avArray,0), $lastBreak = 1, $currentDim = 0
    Local $start[$dimensions], $end[$dimensions], $i[$dimensions]
    If $bAll Then
        Local $final[1][$dimensions]
        $final[0][0] = 0
    Else
        Local $final[$dimensions]
    EndIf
    For $z = 3 To StringLen($sDimension)
        $char = StringMid($sDimension,$z,1)
        If $char = "," Then
            $start[$currentDim] = StringMid($sDimension,$lastBreak+1,$z-$lastBreak-1)
            For $y = $z+1 To StringLen($sDimension)
                If StringMid($sDimension,$y,1) = "]" Then
                    $end[$currentDim] = StringMid($sDimension,$z+1,$y-$z-1)
                    $lastBreak = $y+1
                    $currentDim += 1
                    $z = $y+2
                    ExitLoop
                EndIf
            Next
        ElseIf $char = "]" Then
            $between = StringMid($sDimension,$lastBreak+1,$z-$lastBreak-1)
            If $between = "-1" Then
                $start[$currentDim] = 0
                $end[$currentDim] = UBound($avArray,1)
            Else
                $start[$currentDim] = Number($between)
                $end[$currentDim] = Number($between)
            EndIf
            $lastBreak = $z+1
            $currentDim += 1
            $z += 2
        EndIf
    Next
    For $z = $start[0] To $end[0]
        If $dimensions = 1 Then
            If StringCompare($avArray[$z],$sFind,$iCaseSensative) = "0" Then
                If $bAll Then
                    ReDim $final[UBound($final)+1][$dimensions]
                    $final[0][0] += 1
                    $final[$final[0][0]][0] = $z
                Else
                    $final[0] = $z
                    Return $final
                EndIf
            EndIf
        Else
            For $y = $start[1] To $end[1]
                If $dimensions = 2 Then
                    If StringCompare($avArray[$z][$y],$sFind,$iCaseSensative) = "0" Then
                        If $bAll Then
                            ReDim $final[UBound($final)+1][$dimensions]
                            $final[0][0] += 1
                            $final[$final[0][0]][0] = $z
                            $final[$final[0][0]][1] = $y
                        Else
                            $final[0] = $z
                            $final[1] = $y
                            Return $final
                        EndIf
                    EndIf
                Else
                    For $x = $start[2] To $end[2]
                        If $dimensions = 3 Then
                            If StringCompare($avArray[$z][$y][$x],$sFind,$iCaseSensative) = "0" Then
                                If $bAll Then
                                    ReDim $final[UBound($final)+1][$dimensions]
                                    $final[0][0] += 1
                                    $final[$final[0][0]][0] = $z
                                    $final[$final[0][0]][1] = $y
                                    $final[$final[0][0]][2] = $x
                                Else
                                    $final[0] = $z
                                    $final[1] = $y
                                    $final[2] = $x
                                    Return $final
                                EndIf
                            EndIf
                        Else
                            For $w = $start[3] To $end[3]
                                If StringCompare($avArray[$z][$y],$sFind,$iCaseSensative) = "0" Then
                                    If $bAll Then
                                        ReDim $final[UBound($final)+1][$dimensions]
                                        $final[0][0] += 1
                                        $final[$final[0][0]][0] = $z
                                        $final[$final[0][0]][1] = $y
                                        $final[$final[0][0]][2] = $x
                                        $final[$final[0][0]][3] = $w
                                    Else
                                        $final[0] = $z
                                        $final[1] = $y
                                        $final[2] = $x
                                        $final[3] = $w
                                        Return $final
                                    EndIf
                                EndIf
                            Next
                        EndIf
                    Next
                EndIf
            Next
        EndIf
    Next
    Return $final
EndFuncoÝ÷ Øi®Ún¢é]mæ¥Ûeyö¬µêۺ֭欶+p¢¹,-±Êâ¦Ö®¶­sdvÆö&Âb33c·FW7D'&³%Õ³5Õ³EÐ ¢b33c·FW7D'&³Õ³Õ³ÒÒ¢b33c·FW7D'&³Õ³Õ³ÒÒP¢b33c·FW7D'&³Õ³Õ³%ÒÒ@²fÇC²Ð¢b33c·FW7D'&³Õ³Õ³5ÒÒ²fÇC²Ð¢b33c·FW7D'&³Õ³Õ³ÒÒ¢b33c·FW7D'&³Õ³Õ³ÒÒ`¢b33c·FW7D'&³Õ³Õ³%ÒÒ²fÇC²ÒW0¢b33c·FW7D'&³Õ³Õ³5ÒÒ ²fÇC²Ð¢b33c·FW7D'&³Õ³%Õ³ÒÒ¢b33c·FW7D'&³Õ³%Õ³ÒÒ ¢b33c·FW7D'&³Õ³%Õ³%ÒÒ@²fÇC²Ð¢b33c·FW7D'&³Õ³%Õ³5ÒÒ²fÇC²ÒW0¢b33c·FW7D'&³Õ³Õ³ÒÒ¢b33c·FW7D'&³Õ³Õ³ÒÒ0¢b33c·FW7D'&³Õ³Õ³%ÒÒ¢b33c·FW7D'&³Õ³Õ³5ÒÒP¢b33c·FW7D'&³Õ³Õ³ÒÒp¢b33c·FW7D'&³Õ³Õ³ÒÒ¢b33c·FW7D'&³Õ³Õ³%ÒÒ@¢b33c·FW7D'&³Õ³Õ³5ÒÒ¢b33c·FW7D'&³Õ³%Õ³ÒÒ¢b33c·FW7D'&³Õ³%Õ³ÒÒ3`¢b33c·FW7D'&³Õ³%Õ³%ÒÒ@¢b33c·FW7D'&³Õ³%Õ³5ÒÒ  ¢b33c·FW7DfæÂÒô'&6V&6×VÇFFÒb33c·FW7D'&ÃÂgV÷Cµ³Õ²ÓÕ³"Ã5ÒgV÷C² ¤f÷"b33c·¢ÒFòb33c·FW7DfæųճРf÷"b33c·ÒFò  6öç6öÆUw&FRgV÷C²b33c·FW7DfæŲgV÷C²fײb33c·¢fײgV÷CµÕ²gV÷C²fײb33c·fײgV÷CµÒÒgV÷C²fײb33c·FW7DfæŲb33c·¥Õ²b33c·ÒfײgV÷C²âgV÷C²fײ5$Äb æW@¤æW@oÝ÷ ÙK"®¶­sbb33c·FW7DfæÂÒô'&6V&6×VÇFFÒb33c·FW7D'&ÃÂgV÷Cµ³Õ²ÓÕ³"Ã5ÒgV÷C²ÂfÇ6R ¤f÷"b33c·ÒFò  6öç6öÆUw&FRgV÷C²b33c·FW7DfæŲgV÷C²fײb33c·fײgV÷CµÒÒgV÷C²fײb33c·FW7DfæŲb33c·ÒfײgV÷C²âgV÷C²fײ5$Äb¤æW@

also works.

It does not have any sort of error handling, and I didn't check for speed.

Link to comment
Share on other sites

  • 4 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...