Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jbrave
Channel Surfer

Setting a unique value in an RoArray

Does anyone have a good algorithm for adding an element to an roArray and making sure it is unique? I have history as an roarray and want to make sure that any new search entered using an existing search term does not get added to the list. I also want to limit the size of the array to the maximum number of elements in the history list in the search box.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
3 REPLIES 3
retrotom
Visitor

Re: Setting a unique value in an RoArray

Is there any reason you can't use roAssociativeArray? It uses a key/value pairs and is likely more suited to this. With roArray, you'd have to compare each value in the array. Hopefully roAssociativeArray is O(1) when doing a lookup.
0 Kudos
jbrave
Channel Surfer

Re: Setting a unique value in an RoArray

The history parameter of a search screen takes an roarray as it's parameter
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
retrotom
Visitor

Re: Setting a unique value in an RoArray

Yeah, so why not take each item in the history roArray and enter it into a roAssociativeArray? Do a lookup before adding a new value to the search history. If you load the roAssociativeArray at application startup, then you can scan then history array once -- and before adding something to the history, you can just do a quick lookup in the roAA. As you add things to history, you can also add to the associative array. Assuming the roAA DoesExist function is O(1), this is more efficient from a performance standpoint and definitely from a coding standpoint. If case sensitivity ever becomes a concern (unlikely), then you have that built in too.
0 Kudos