Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 217143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:37:48+00:00 2026-05-11T18:37:48+00:00

As part of a test bench I’m building, I’m looking for a simple class

  • 0

As part of a test bench I’m building, I’m looking for a simple class to calculate a histogram of integer values (number of iterations taken for an algorithm to solve a problem). The answer should be called something like this:

Histogram my_hist = new Histogram();

for( uint i = 0; i < NUMBER_OF_RESULTS; i++ )
{

    myHist.AddValue( some_result );
}

for( uint j = 0; j < myHist.NumOfBins; j++ )
{
     Console.WriteLine( "{0} occurred {1} times", myHist.BinValues[j], myHist.BinCounts[j] );
}

I was suprised a bit of googling didn’t turn up a neat solution but maybe I didn’t search for the right things. Is there a generic solution out there or is it worth rolling my own?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:37:48+00:00Added an answer on May 11, 2026 at 6:37 pm

    You could use SortedDictionary

    uint[] items = new uint[] {5, 6, 1, 2, 3, 1, 5, 2}; // sample data
    SortedDictionary<uint, int> histogram = new SortedDictionary<uint, int>();
    foreach (uint item in items) {
        if (histogram.ContainsKey(item)) {
            histogram[item]++;
        } else {
            histogram[item] = 1;
        }
    }
    foreach (KeyValuePair<uint, int> pair in histogram) {
        Console.WriteLine("{0} occurred {1} times", pair.Key, pair.Value);
    }
    

    This will leave out empty bins, though

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some .csv files which I'm using as part of a test bench.
I want to test my part of code that returns the users password question.
I am writing a junit test in order to (surprisingly) test a part of
As part of a disaster recovery test of our TFS 2008 instance I hoped
I have built part of my app and wanted to test it out. All
My team and I are designing a diagnostic test tool as part of our
In another question I asked (why is Rake test so slow ), part of
I am doing some simple sanity validation on various types. The current test I'm
In CPP unit we run unit test as part of build as part of
I am looking at ways to automate testing of an Android app widget. Part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.