Jump to content

_ArraySearch "bug" ? - (Moved)


TommyDDR
 Share

Recommended Posts

Hi,

It's not possible to search only in the first entry of an array with _ArraySearch.

Indeed :

; Bounds checking
    If $bRow Then
        If UBound($aArray, $UBOUND_DIMENSIONS) = 1 Then Return SetError(5, 0, -1)
        If $iEnd < 1 Or $iEnd > $iDim_2 Then $iEnd = $iDim_2
        If $iStart < 0 Then $iStart = 0
        If $iStart > $iEnd Then Return SetError(4, 0, -1)
    Else
        If $iEnd < 1 Or $iEnd > $iDim_1 Then $iEnd = $iDim_1
        If $iStart < 0 Then $iStart = 0
        If $iStart > $iEnd Then Return SetError(4, 0, -1)
    EndIf

If $iEnd = 0, then _ArraySearch process the entire array.

 

I think the default value should be -1 and not 0 fot $iEnd

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Link to comment
Share on other sites

I'm afraid it's too late to fix due to the number of real-world scripts already relying on this convention, admitedly weird.

OTOH, "searching" a given single row in an array amounts to directly comparing "searched" column(s) of row index N with search value(s). That's true whatever the searched row index is, 0 or not. So this point is rather moot.

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)

Link to comment
Share on other sites

Here is an exemple where the problem can happen :

#include <Array.au3>

Global $topPoints = [["Jos", 1000], ["jchd", 900], ["TommyDDR", 800]]
Global $playerToFind = "TommyDDR"

For $i = 3 To 1 Step -1
    Local $top = isTopPoints($playerToFind, $i-1) ? " is in TOP " : " is not in TOP "
    ConsoleWrite($playerToFind & $top & $i & @CRLF)
Next

Func isTopPoints($player, $nbMax)
    Return _ArraySearch($topPoints, $player, 0, $nbMax) >= 0
EndFunc

Result will be :

TommyDDR is in TOP 3
TommyDDR is not in TOP 2
TommyDDR is in TOP 1

Instead of :

TommyDDR is in TOP 3
TommyDDR is not in TOP 2
TommyDDR is not in TOP 1

Does it really break many script ?

I think many of us don't send any parameter when all array have to be processed, si if it's changed internally to -1, we can't see the difference.

But i know that changing such a basic function after a long period of use can be touchy.

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Link to comment
Share on other sites

I guess how it is now is correct? You would never search a singular item because you wouldn't need to search it.

image.png.e095d301440a3d46e6034a5cbe2102ea.png

You wouldn't search among the rock. You'd just check to see if the rock was what you was looking for?

#include <Array.au3>

Global $topPoints = [["Jos", 1000], ["jchd", 900], ["TommyDDR", 800]]
Global $playerToFind = "TommyDDR"

For $i = 3 To 1 Step -1
    Local $top = isTopPoints($playerToFind, $i-1) ? " is in TOP " : " is not in TOP "
    ConsoleWrite($playerToFind & $top & $i & @CRLF)
Next

Func isTopPoints($player, $nbMax)
    If $nbMax = 0 Then
        Return ($topPoints[0][0] = $player)
    Else
        Return _ArraySearch($topPoints, $player, 0, $nbMax) >= 0
    EndIf
EndFunc

 

Link to comment
Share on other sites

1 hour ago, TommyDDR said:

Does it really break many script ?

I think many of us don't send any parameter when all array have to be processed, si if it's changed internally to -1, we can't see the difference.

Yes, actually many scripts IMVHO: just because there are useful parameters passed after $iEnd, like case sensivity, comparison method (text vs. numeric), subitems (2D arrays) and the like. Without a way to omit intermediate parameters like in _ArraySearch($a, $sSearch, 5, , , 3) I see the issue as difficult to solve.

The only proper way to solve the problem would be to propose _ArraySearchEx() with smarter defaults.

Edited by jchd

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)

Link to comment
Share on other sites

this better code if you want to use it:

#include <Array.au3>

Global $topPoints = [["Jos", 1000], ["jchd", 900], ["TommyDDR", 800]]
Global $playerToFind = "TommyDDR"
For $i = 0 To UBound($topPoints)-1 Step 1
    if $topPoints[$i][0] = $playerToFind  Then
       ConsoleWrite($playerToFind & " is in TOP " &$i &@CRLF)
    Else
          ConsoleWrite($playerToFind & " is not in TOP " &$i&@CRLF)
       EndIf
Next

 

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
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
 Share

  • Recently Browsing   0 members

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