473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Generic Dictionary For Keys Only?

All,

I have a situation where I need a List<stringthat performs like a
generic dictionary (Dictionary<string, string>). Essentially, I just
need the key, not the value, so I want to use as little memory as
possible. Currently I am setting all the values of the dictionary to
null.

The List<stringdoesn't work because I am doing a lot of .Contains()
or .ContainsKey(), and lookup speed is pretty critical.

So, does such a thing exist? A dictionary that only uses a key, with
no value? Or does making the value null eliminate any memory overhead
anyway?
Thanks for any insight.

Phil
Jun 27 '08 #1
3 2003
On May 27, 3:17 pm, Phil Sandler <psandle...@hotmail.comwrote:

<snip>
So, does such a thing exist? A dictionary that only uses a key, with
no value? Or does making the value null eliminate any memory overhead
anyway?
What you're after is a set, basically. There *is* one in .NET 3.5:
System.Collections.Generic.HashSet. If you're not using .NET 3.5, I
don't believe there's one available in the framework - it's easy to
build the right interface using Dictionary, although that won't get
you any efficiency improvements.

How many elements are you likely to have in here? In many cases any
resource usage improvement will be negligible.

Jon
Jun 27 '08 #2
[...]

On May 27, 11:44 am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
What you're after is a set, basically. There *is* one in .NET 3.5:
System.Collections.Generic.HashSet. If you're not using .NET 3.5, I
don't believe there's one available in the framework - it's easy to
build the right interface using Dictionary, although that won't get
you any efficiency improvements.

How many elements are you likely to have in here? In many cases any
resource usage improvement will be negligible.
We are not currently using 3.5--not sure if we need VS2008 to get
there? If so, we probably can't do so on this project; if not, then
it might be worth it if these Hashsets would make a big difference.

There will be a number of these collections in the system, of varying
sizes. The biggest ones may have at most 100K items in the list, with
(probably) a max of 20 lists of this size. The rest of the lists will
be small, probably no more than a few hundred items.

Thanks for your response.

Phil
Jun 27 '08 #3
Phil Sandler <ps********@hotmail.comwrote:
How many elements are you likely to have in here? In many cases any
resource usage improvement will be negligible.

We are not currently using 3.5--not sure if we need VS2008 to get
there? If so, we probably can't do so on this project; if not, then
it might be worth it if these Hashsets would make a big difference.
Yes, you need VS2008 to use .NET 3.5. Of course, there are other big
reasons for using VS2008 - all the goodness of C# 3, for one thing.

I do understand the need to not change technologies mid-project,
however.
There will be a number of these collections in the system, of varying
sizes. The biggest ones may have at most 100K items in the list, with
(probably) a max of 20 lists of this size. The rest of the lists will
be small, probably no more than a few hundred items.
Well, do a test - but I doubt it will cost you vast amounts of
resources.

You may well find there are free 3rd party implementations around.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: none | last post by:
or is it just me? I am having a problem with using a dictionary as an attribute of a class. This happens in python 1.5.2 and 2.2.2 which I am accessing through pythonwin builds 150 and 148...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
12
by: Elhanan | last post by:
hi.. i wanted to build a Dictionary Classs that will load my own class called letter, i understood that i implement the IEquatable interface's equles method that then the dictionary would use...
4
by: Adam Clauss | last post by:
I ran into a problem a while back when attempting to convert existing .NET 1.1 based code to .NET 2.0 using Generic collections rather than Hashtable, ArrayList, etc. I ran into an issue because...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
14
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a...
6
by: fstorck | last post by:
Hi, I'm looking for a generic version of a map container that acts similar like the multimap known from C++ / STL . <code> Dictionary<string, myobjectmap = new Dictionary<string,...
7
by: Sehboo | last post by:
We have several generic List objects in our project. Some of them have about 1000 items in them. Everytime we have to find something, we have to do a for loop. There is one method which does the...
5
by: Ethan Strauss | last post by:
Hi, I have just started using Generic Collections for .Net 2.0 and so far they are working very nicely for me. But, I do have a couple of questions. If I have a Generic collection which has a type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.