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 8578821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:28:50+00:00 2026-06-11T20:28:50+00:00

I have a rather general question regarding the recognition speed of any dictionary using

  • 0

I have a rather general question regarding the recognition speed of any dictionary using a string as a key and couldn’t find an answer so far.

Within my current program I have a dictionary of custom objects but the keys I use are filenames including the whole path of the file such that no key can actually occur twice.

My question is: Does the time to find the specific object within the dictionary significantly depend on the length of the string used as a key? Afterall, if I have a big amount of data saved within my object and I use that data in a loop and access the data every single time by using myDictionary[Key]. The simple recognition might take a long time, making the loops last for a longer time.

My solution to this problem would be: In case of using an array, lets say double[,,] within my object, I temporarily create a new array and set this one equal to the one within the dictionary, so I don’t have to search through the dictionary for every single loop iteration.

  • 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-06-11T20:28:51+00:00Added an answer on June 11, 2026 at 8:28 pm

    Does the time to find the specific object within the dictionary
    significantly depend on the length of the string used as a key?

    Yes it does. Finding an element in a dictionary is done with two CPU intensive steps:

    1. Generate the hash code for the key.
    2. Comparing all elements in the same bucket by equality.

    A dictionary stores elements in buckets. To be able to do an O(1) lookup, the dictionary calculates the position in the internal array using hashCode modulo array.Length. This can result in elements with the same index. Those elements are stored under the same index; which is called a bucket.

    For a string, the hash code is generated using all characters in the string, which mean that the generation of the string’s hash code has a performance characteristic of O(n). When the string is big, it takes longer to generate the hash code. Comparing to strings for equality is done by comparing two strings completely. If these strings contain, let’s say, 100,000 characters and only the last character differs, comparing the two strings can take quite a lot of time. If they differ with the first character, the comparison will return false very quickly. Determining that two strings are in fact equal (if they aren’t reference equal) takes the most time, since the complete string needs to be traversed.

    If you can, make key strings short if the dictionary is in a performance critical path of the application.

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

Sidebar

Related Questions

I have a rather general question regarding JavaScript and local variables. My question is
sorry for my rather general question, but I could not find a definite answer
I have a general question that is rather open-ended (i.e. depends on platform, application
I have a rather basic and general question about atomicity of UPDATE ... SET
I have a general question regarding UITableViews. here is my situation. I have a
Have a rather simple question. Does anyone knows if i can use jparallax both
I have general question that if an asp.net webmethod always returns data in 'json'
this time I got a more general question. Should I use multiple views rather
This is a rather general question .. What hardware setup is best for large
I have a rather simple question for you.. I feel like I should have

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.