Page 1 of 1

Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 1:09 am
by matalog
I have 250 Numbers that link to 250 Names.

I will be scanning a barcode and receiving a number which should be one of the 250 numbers.

Which of List, array or Map would allow me to search all the numbers for the current input number the simplest?

I have currently got then stored in an array, but I'm not sure if an array can be searched like I need.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 1:19 am
by skywalk
Map().s works great for this.

debug myMap(Str(SomeBarCodeNumber))

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 4:46 am
by Opcode
Map would be best with predefined values since you don't need to waste cycles iterating through an array or list.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 6:15 am
by Denis
Same for me, MAP

Is the speed really critical?
Have you tested all 3?
If so, did you feel a real difference ?

The number of values is small (250), maybe it doesn't matter here.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 10:53 am
by infratec
If you always get an 'index' (0...250) and all of them are in use, then I would prefer the array.
You don't need to search, because your received number is the index of the array.

This is faster and need less memory then a map.
And since the count is fixed and you need not append elements, an array is the best solution.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 1:07 pm
by skywalk
Does the barcode api return a string or an integer?

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 5:51 pm
by matalog
infratec wrote: Sat Mar 18, 2023 10:53 am If you always get an 'index' (0...250) and all of them are in use, then I would prefer the array.
You don't need to search, because your received number is the index of the array.

This is faster and need less memory then a map.
And since the count is fixed and you need not append elements, an array is the best solution.
Well, no the barcodes I have are not the numbers 0 to 250, it that what you meant?

I think I might map the barcode numbers to an Index, then use an array, to hold any other details I need.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 5:54 pm
by matalog
skywalk wrote: Sat Mar 18, 2023 1:07 pm Does the barcode api return a string or an integer?
I have not received the device yet, but I have been led to believe it will give the number in ascii format, so - String.

Re: Choosing between List, Array and Map

Posted: Sat Mar 18, 2023 7:54 pm
by idle
Use a map especially if it returns a string