Hi guys
I’ve an unordered list of terms which I’d like to compress. Let me explain.
The following list
[ 1, 2, 1, 1, 15, 3, 2 ]
has to be compressed like this:
[ {1,3}, {2,2}, {15,1}, {3,1} ]
or:
[ {3,1}, {2,2}, {1,3}, {15,1} ]
1
appeared 3x times in the original list. Similarly, 2
appeared 2x times, etc. Ordering of elements in compressed list isn’t important here. As long as the list is compressed, I’m ok with it.
While an algorithm to achieve this seems more or less obvious (I tried maps
, dict
, process dictionary
, and ETS
table), I couldn’t come up with a solution which scales well for a list of ~10Mil
elements.
> crypto:start().
> L = [crypto:rand_uniform(1, 100000) || _ <- lists:seq(1, 10000000)]. %% not sure if this is the best way to generate random number
> mylist:compress(L). ???? anyone
Help appreciated.