How to safely delete entries from a queue

In reply to mseyunni:
Queues are optimal for adding/deleting items to/from the head or tail of the queue. It would be much more efficient to use an associative array.

int  id_aa[int];

foreach(id_aa[i])
  if(id_aa[i] == 'h1b) 
    id_aa.delete(i);

// alternatively if you expect large arrays and small number of matching items
int index_cu[$];

index_cu      = id_aa.find_index() with (item == 'h1b);
foreach(index_cu[i]) 
   id_aa.delete(index_cu[i]);

The reason your foreach loop with a queue doesn’t work is that every time you delete an item, the next item is moved into the current index that you just compared, and is skipped over. You could do:

for(int i = 0; i<id_q.size(); i++)
  if(id_q[i] == 'h1b)
    id_q.delete(i--);