title: What is the fastest way to calculate frequency distribution for array in C#?
body: <p>I am just wondering what is the best approach for that calculation. Let's assume I have an input array of values and array of boundaries - I wanted to calculate/bucketize frequency distribution for each segment in boundaries array.</p>
  
  <p>Is it good idea to use bucket search for that?</p>
  
  <p>Actually I found that question <a href="https://stackoverflow.com/questions/1598282/calculating-frequency-distribution-of-a-collection-with-net-c">Calculating frequency distribution of a collection with .Net/C#</a></p>
  
  <p>But I do not understand how to use buckets for that purpose cause the size of each bucket can be different in my situation.</p>
  
  <p>EDIT:
  After all discussions I have inner/outer loop solution, but still I want to eliminate the inner loop with a Dictionary to get O(n) performance in that case, if I understood correctly I need to hash input values into a bucket index. So we need some sort of hash function with O(1) complexity? Any ideas how to do it?</p>