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

  • Home
  • SEARCH
  • 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 71745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:56:10+00:00 2026-05-10T19:56:10+00:00

I have what is essentially a jagged array of name value pairs – i

  • 0

I have what is essentially a jagged array of name value pairs – i need to generate a set of unique name values from this. the jagged array is approx 86,000 x 11 values. It does not matter to me what way I have to store a name value pair (a single string ‘name=value’ or a specialised class for example KeyValuePair).
Additional Info: There are 40 distinct names and a larger number of distinct values – probably in the region 10,000 values.

I am using C# and .NET 2.0 (and the performance is so poor I am thinking that it may be better to push my entire jagged array into a sql database and do a select distinct from there).

Below is the current code Im using:

List<List<KeyValuePair<string,string>>> vehicleList = retriever.GetVehicles(); this.statsLabel.Text = 'Unique Vehicles: ' + vehicleList.Count;  Dictionary<KeyValuePair<string, string>, int> uniqueProperties = new Dictionary<KeyValuePair<string, string>, int>(); foreach (List<KeyValuePair<string, string>> vehicle in vehicleList) {     foreach (KeyValuePair<string, string> property in vehicle)     {         if (!uniqueProperties.ContainsKey(property))         {             uniqueProperties.Add(property, 0);         }     } } this.statsLabel.Text += '\rUnique Properties: ' + uniqueProperties.Count; 
  • 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. 2026-05-10T19:56:10+00:00Added an answer on May 10, 2026 at 7:56 pm

    I have it running in 0.34 seconds down from 9+ minutes

    The problem is when comparing the KeyValuePair structs. I worked around it by writing a comparer object, and passing an instance of it to the Dictionary.

    From what I can determine, the KeyValuePair.GetHashCode() returns the hashcode of it’s Key object (in this example the least unique object).

    As the dictionary adds (and checks existence of) each item, it uses both Equals and GetHashCode functions, but has to rely on the Equals function when the hashcode is less unique.

    By providing a more unique GetHashCode function, it excerises the Equals function far less often. I also optimised the Equals function to compare the more unique Values before the less unqiue Keys.

    86,000 * 11 items with 10,000 unique properties runs in 0.34 seconds using the comparer object below (without the comparer object it takes 9 minutes 22 seconds)

    Hope this helps 🙂

        class StringPairComparer         : IEqualityComparer<KeyValuePair<string, string>>     {         public bool Equals(KeyValuePair<string, string> x, KeyValuePair<string, string> y)         {             return x.Value == y.Value && x.Key == y.Key;         }         public int GetHashCode(KeyValuePair<string, string> obj)         {             return (obj.Key + obj.Value).GetHashCode();         }     } 

    EDIT: If it was just one string (instead of a KeyValuePair, where string = Name+Value) it would be approx twice as fast. It’s a nice intresting problem, and I have spent faaaaaar too much time on it (I learned quiet a bit though)

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

Sidebar

Related Questions

I have a simple class that essentially just holds some values. I have overridden
I have essentially a survey that is shown, and people answer questions a lot
If you have to use String.Replace() to replace test 50 times, you essentially have
I am currently trying to manipulate a unordered list with jQuery, essentially I have
i have a Sharepoint feature that essentially extends Lists with a new feature, using
Essentially, I have to get a flat file into a database. The flat files
I have a mockup layout for something here . Essentially there are sections, columns
So What I'm essentially trying to do is have something happen 70% of the
We have a reverse proxy here, running Apache in version 2.2.x Essentially I want
I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty

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.