All,
I have a situation where I need a List<stringthat performs like a
generic dictionary (Dictionary<str ing, 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<stringdoes n'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 3 2019
On May 27, 3:17 pm, Phil Sandler <psandle...@hot mail.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.Collecti ons.Generic.Has hSet. 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
[...]
On May 27, 11:44 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
What you're after is a set, basically. There *is* one in .NET 3.5:
System.Collecti ons.Generic.Has hSet. 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
Phil Sandler <ps********@hot mail.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.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 respectively
In the sample code you see that I have class Item and class Dict
class Dict contains a dictionary called items. The items dictionary
will contain instances of Item that are keyed off of the Item name. In
__main__ I create two...
|
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 a single
collections type, I should be proposing a new "namespaces" module
instead. Some of my reasons:
(1) Namespace is feeling less and less like a collection to me. Even
though it's still intended as a data-only structure, the use cases...
|
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 that inorder to compare the keys, so
i went ahead the implented it in the LETTER class so letter would
provice it's own means for comparison, but the dictionary ignored it
only when i created a new class, called it letterkey ,had it implement
|
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 the old code allowed me to do what basically was
the following assignment:
class SomeClass
{
private Queue q;
SomeClass(Queue q)
|
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 expensive is it to instantiate/use Generic Dictionaries in great
numbers (let's just say 100000's ), in terms of memoryuse and performance?
Any practical experiences out there?
| |
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 list? I
know that sets were introduced a lot later and lists/dictionaries were
used instead but I think "the only correct way" now is for the
dictionary keys and values to be sets. Presently {1:0,2:0,3:0}.keys()
will produce but it could also...
|
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, myobject>();
map.Add("CATEGORY1", new myobject());
|
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
searching, but that method receives the object, and the string to
search in that object and runs the FOR loop to find the answer.
This is taking time because we have to do searching hundres of times.
I want to use Hashtable, but the problem...
|
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 which is a reference type,
is there a way to get Collection.ContainsKey(RefKey) and Collection
to work with different instances of equal keys?
For example, I have defined a class of "codon" and I have made a dictionary
private...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |