title: Count distinct values in array - performance tips
body: <p>I'm having some issues optimizing a go map.<br>
  I want to generate a frequency table (count distinct occurrences) in an array of strings. My code holds nicely for small arrays, but as I start working with 100k+ structures -with many distinct values- it just isn't performant enough.</p>
  
  <p>Right now, my approach is to generate an array with the distinct values, compare values and increasing the counter variable (mapped to the string). </p>
  
  <pre><code>    counter := make( map[string]int )    
      for _, distinct := range distinctStrArray{
          for _, row := range StrArray{
              if (row == distinct){
                  counter[distinct]++
              }  
          } 
      }
  </code></pre>
  
  <p>I've tried another approach, where with the input array previously sorted (to minimize the number of changes to the map). This is a bit faster. </p>
  
  <pre><code>    count:=0
      for _, distinct := range distinctStrArray{
          for _, row := range StrArray{
              if (row == distinct){
                  count++
              }  
          } 
      counter[distinct] += count
      count= 0
      } 
  </code></pre>
  
  <p>Do you have any suggestion of what I can do to optimize a simple <em>count(distinct)</em> type problem...? I'm open to anything.<br>
  thanks!</p>