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.
Choosing between List, Array and Map
Choosing between List, Array and Map
Last edited by matalog on Sat Mar 18, 2023 1:19 am, edited 1 time in total.
Re: Choosing between List, Array and Map
Map().s works great for this.
debug myMap(Str(SomeBarCodeNumber))
debug myMap(Str(SomeBarCodeNumber))
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Choosing between List, Array and Map
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
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.
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
Denis
Re: Choosing between List, Array and Map
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.
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
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
Re: Choosing between List, Array and Map
Well, no the barcodes I have are not the numbers 0 to 250, it that what you meant?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.
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
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
Use a map especially if it returns a string