Check for existence of element in queue

Hi,

I have a queue which will is filled with some enum value. i would like to check if the element exists in queue and assign 1 to map if it exists.

typedef enum {A,B,C,....Z} alphabet;

class try;
alphabet var_q[$];
bit  map[32];

//in pre randomize, assign the map variable to 1 if element exist in queue 
function void pre_randomize();
   foreach(map[i]) begin
        map[i] =  !((var_q.find(x) with (x == i)).size() == 0);
   end
endfunction 

endclass

DO you see any issue with above code? or is there better way to do it ?

Thanks

endclass

In reply to sv_uvm_learner_1:
Depending on the size of the var_q, it might be more efficient to do:

foreach (var_q[e]) map[var_q[e]] = 1;