I have an array of addresses and a function which returns how many times an address is in the array. For example, if the array has ['0x00', '0x01', '0x00'] the function will return 2 for 0x00 and 1 for 0x01
I would like to know if my approach is efficient enough to work with a large number of addresses
address[] public users;
function userCounter(address user) public view returns(uint){
uint counter;
for(uint i; i<users.length; i++){
if(users[i] == user){
counter++;
}
}
return counter;
}
Any idea how I could improve it? Currently it takes a while to iterate over 300 elements so I imagine how bad it's going to be for a larger number.