I have n different unique unsigned 32-bit integers. For each integer in for-loop I will generate a random index (address) and I want to put that number is a set specified by that index (address). For example in for-loop I reach to number 7 and my code produces 13 as address, then I need to add the number 7 to the 13th set. Having index (address) range of 1 to k, I will need k different sets. Currently I am using "cell" data structure in MATLAB.
array_of_sets=cell(n,1);
and when I want to add new member to ith set, I will index by array_of_sets{i} and then I will concatenate my new number.
My problem is that this approach is not memory efficient nor time efficient. Can anyone please guide me to a more efficient way to do this.
This is a simplified version my code so far:
array_of_sets=cell(k,1);
for i=1:n
address=something_genrated_randomly;
array_of_sets{address}=[array_of_sets{address},uint32(i)]; %Add to the corresponding set(One specific Cell)
end
Output: Given the index ind, outputs the the ind^th set of integers.
Basically what I am looking for is similar to ArrayList<Set<Integer>>
from Java but in MATLAB.