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: 
MarkRoddy
Visitor

Number of Entries in an roAssociativeArray

It strikes me as kind of odd that there's no method on the roAssociativeArray object to access the number of entries it has, at least it's no listed in section 10.13 of the BrightScript Reference doc which lists all the methods for this class. Is there method that's missing from the documentation to accomplish this or do I need to an O(n) operation like below to determine the size of an associative array?

-Mark


Function AssocArrayCount(aa as object) as Integer
'Returns the number of entries in an roAssociativeArray
i = 0
for each k in aa
i = i + 1
end for
return i
End Function
0 Kudos
2 REPLIES 2
bbefilms
Visitor

Re: Number of Entries in an roAssociativeArray

add a key, i.e. 'length' and increment/decrement it when pushing/popping values?
0 Kudos
MarkRoddy
Visitor

Re: Number of Entries in an roAssociativeArray

"bbefilms" wrote:
add a key, i.e. 'length' and increment/decrement it when pushing/popping values?


I'm working on a function to compare two roAssociativeArrays for equality for brstest, so I won't know whether or not the user has done so before hand, but a decent idea for the non-general case.

Unfortunately for my case I'm comparing two of them so it's actually a O(n+m) operation to check for equality.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.