Q:

How to efficiently find which array in a set of array has members

How do I efficiently find which array in a list of array has members. 
The context is for message brokering. I have a list of queue and need to periodically push their content to consumers, but since the number of queues can be large, I want to quickly find out which ones have elements in them.
My only solution currently is to basically keep a separate list which keeps track of which array still has content in it, but was curious about alternatives, and it just bugs the hell out of me ;)
I am using javascript but am hoping for a more general idea of which algorihtm should I look into.

A:

I'm going to make this language-agnostic and keep my answer short and simple.
Maintain a parallel data-structure: another set storing array IDs, but only those of arrays that are nonempty.

When you make a new (empty) array, add it to the first set only.
When you add to an array, add it to the second set iff it's not already there.
When you remove from an array, if the array is now empty, remove it from the second set.
When you delete an array, remove it from the the first set (and the second, if it's there).

If you're using a hashset for this second set, insertion and deletion times don't change.  This is the most efficient thing one could ask for, and a hybrid datastructure of this ilk is necessary AFAICT.
You can then find all nonempty arrays by iterating over the second set.

