Choosing between List, Array and Map

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Choosing between List, Array and Map

Post 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.
Last edited by matalog on Sat Mar 18, 2023 1:19 am, edited 1 time in total.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Choosing between List, Array and Map

Post by skywalk »

Map().s works great for this.

debug myMap(Str(SomeBarCodeNumber))
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Re: Choosing between List, Array and Map

Post by Opcode »

Map would be best with predefined values since you don't need to waste cycles iterating through an array or list.
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Choosing between List, Array and Map

Post 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.
A+
Denis
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Choosing between List, Array and Map

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Choosing between List, Array and Map

Post by skywalk »

Does the barcode api return a string or an integer?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Choosing between List, Array and Map

Post 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.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Choosing between List, Array and Map

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5835
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Choosing between List, Array and Map

Post by idle »

Use a map especially if it returns a string
Post Reply