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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:29:31+00:00 2026-05-13T13:29:31+00:00

I have a problem where I need a .NET dictionary that supports multiple items

  • 0

I have a problem where I need a .NET dictionary that supports multiple items per key. In the past I’ve used the STL multimap in my C++ programs. How does the design of a multimap differ from a dictionary of lists i.e. performance, size, etc. (excluding generics vs. templates)?

  • 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-13T13:29:32+00:00Added an answer on May 13, 2026 at 1:29 pm

    multimap.count: O(log n + m) where n is number of keys and m is number of items associated with a given key.

    For a Dictionary<TKey, List<TValue>> the equivalent functionality would be:

    int count = dictionary[key].Count;
    

    And safer is to say

    int count;
    List<TValue> list;
    if(dictionary.TryGetValue(key, out list)) {
        int count = list.Count;
    }
    

    This is an O(1) operation because lookup is O(1)1 and List<T>.Count is O(1).

    multimap.find: O(log n) where n is number of keys

    For a Dictionary<TKey, List<TValue>> the equivalent functionality would be:

    List<TValue> elements = dictionary[key];
    

    And safer is to say

    List<TValue> list;
    if(dictionary.TryGetValue(key, out list)) {
        // safe to iterate list
    }
    

    This is O(1). See the previous remark on lookup by key in a Dictionary<TKey, TValue>.

    multimap.insert: O(log n) where n is the number of keys.

    For a Dictionary<TKey, List<TValue>> the equivalent functionality would be:

    // value is TValue to insert
    List<TValue> list;
    if(!dictionary.TryGetValue(key, out list)) {
        list = new List<TValue>();
        dictionary.Add(key, list);
    }
    list.Add(value);
    

    This is usually O(1) but can be O(n) when the capacity of the dictionary must be increased to accomodate the new element.

    multimap.remove: There are three overloads of this method; I will only consider the one that accepts a key and removes all occurrences of that key from the multimap. This is an O(log n + m) operation where there n keys and m objects associate with a given key.

    For a Dictionary<TKey, List<TValue>> the equivalent functionality would be:

     dictionary.Remove(key);
    

    From the documentation: “This method approaches an O(1) operation.” Same comment applies.

    1: From the documentation: “Retrieving a value by using its key is very fast, close to O(1).” Why the documentation is vague on this point is confusing to me. Either an operation is O(1) or it isn’t. There is no such thing as “close” to O(1).

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

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First, put an autorelease pool in your main() to shut… May 16, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer Yes you put your code in a file and include… May 16, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer Returns true if the string can be entered with the… May 16, 2026 at 11:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a wierd problem that i need to work out how to resolve,
I have many, (15-20) different XML files that I need to load to VB.Net.
I have a C#.net app I need to run off a computer. It has
I need to solve the following problem for one of my clients. They have
using: VS2008, C# I have a COM dll I need to use in a
I have been struggling to get a simple DynamicObject example working in .NET 3.5.
i'm trying to use OutputCaching in my ASP.NET MVC website. Problem is, when i
I have a problem with the 'update' hook. In the case of a new
I have an ASP.NET content page. The HTML tag associated with the content page
I have my ASP.NET MVC 2 application divided into few areas. One of them

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.