Sign in to follow this  
Followers 0
amirc

what is the fastest way to search in array?

9 posts in this topic

#1 ·  Posted (edited)

ok i did a fucntion:

func get_id($code,$list)
         local $i,$result
         $result = -1; return -1 at error
         for $i = 0 to Ubound($list)-1
                 if $list[$i][1] = $code then
                        $result = $i
                        exitloop
                 endif
         next
         return $result
endfunc

is ther any better way to do it?

Edited by amirc

Share this post


Link to post
Share on other sites



ok i did a fucntion:

func get_id($code,$list)
         local $i,$result
         $result = -1; return -1 at error
         for $i = 0 to Ubound($list)-1
                 if $list[$i][1] = $code then
                        $result = $i
                        exitloop
                 endif
         next
         return $result
endfunc

is ther any better way to do it?

Depends if it is sorted,. because if it is you can use _ArrayBinarySearch().

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

for $i = 0 to Ubound($list)-1

Does the '0' store a needed variable for you? If not you could replace it with '1' which is normally the case with Ubound()-1 in my experience.

There's no other information provided other than the loop really, so... I'd have to say 'Who Knows' if there is a better way without seeing what it is your sending to the function. If it works, then it looks good :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

i will give you exmple of what in side the array

$list[0][0] = 'black lotus' ; card name

$list[0][1] = 12342355155 ; pixlechecksum of the card

$list[0][2] = 1 ; buying prise

$list[0][3] = 2 ; selling prise

ther are lots(100-200) of cards names with diffrent buy\sell prises and

diffrent pixlechecksum.

Share this post


Link to post
Share on other sites

i will give you exmple of what in side the array

$list[0][0] = 'black lotus' ; card name

$list[0][1] = 12342355155 ; pixlechecksum of the card

$list[0][2] = 1 ; buying prise

$list[0][3] = 2 ; selling prise

ther are lots(100-200) of cards names with diffrent buy\sell prises and

diffrent pixlechecksum.

Well, as said ... if the whole array is sorted in alphabetical order, the binary search is the fastest method.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

witch one need to be alphabetical?

the card name?

or the PixleCheckSum?

Share this post


Link to post
Share on other sites

how can i sort it?

what to write as a parameter at: _ArraySort()

_ArraySort($list[][1]) ?

Share this post


Link to post
Share on other sites

how can i sort it?

what to write as a parameter at: _ArraySort()

_ArraySort($list[][1]) ?

_ArraySort ( ByRef $a_Array, [$i_Descending[, $i_Base=0[, $i_Ubound=0[, $i_Dim=1[, $i_SortIndex=0]]]]] )

so I would say: _ArraySort ( $list, 0, 0, 0, 2, 1)

:P


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
Sign in to follow this  
Followers 0