473,387 Members | 1,486 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,387 software developers and data experts.

Generic MultiMap class / Set like the STL one...

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());
map.Add("CATEGORY1", new myobject(); // <-- this is not possible here,
// because the Net 2.0 Dictionary
only supports
// unique keys.

</code>

It should support multiple objects per key.

Does anybody have a good solution / code for this ? And by the way, I heard
of STLNET ? But as I understood, this is only for C++ available ? Or does
this work under C# ( I found no documentation abaout this so far).

Thanks,
Florian

Aug 21 '06 #1
6 6100
I think it's easy to make a custom collection like this yourself based
on the existing ones, or you can use something like this:

Dictionary<string, List<myobject>map = new Dictionary<string,
List<myobject>>();

map.Add("CATEGORY1", new List<myobject>());
map["CATEGORY1"].Add(new myobject());
map["CATEGORY1"].Add(new myobject());
fstorck wrote:
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());
map.Add("CATEGORY1", new myobject(); // <-- this is not possible here,
// because the Net 2.0 Dictionary
only supports
// unique keys.

</code>

It should support multiple objects per key.

Does anybody have a good solution / code for this ? And by the way, I heard
of STLNET ? But as I understood, this is only for C++ available ? Or does
this work under C# ( I found no documentation abaout this so far).

Thanks,
Florian
Aug 21 '06 #2
Hi Wiebe,

ouch, looks pretty obvious. Ok, it's worth a try. BTW, anything heard of
this STLNET stuff. Is my intepretation correct ? If it's .Net based, it
should work fine with C# but I've not idea where to look for...
"Wiebe Tijsma" wrote:
I think it's easy to make a custom collection like this yourself based
on the existing ones, or you can use something like this:

Dictionary<string, List<myobject>map = new Dictionary<string,
List<myobject>>();

map.Add("CATEGORY1", new List<myobject>());
map["CATEGORY1"].Add(new myobject());
map["CATEGORY1"].Add(new myobject());
fstorck wrote:
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());
map.Add("CATEGORY1", new myobject(); // <-- this is not possible here,
// because the Net 2.0 Dictionary
only supports
// unique keys.

</code>

It should support multiple objects per key.

Does anybody have a good solution / code for this ? And by the way, I heard
of STLNET ? But as I understood, this is only for C++ available ? Or does
this work under C# ( I found no documentation abaout this so far).

Thanks,
Florian
Aug 21 '06 #3
Hi,

I didn't look at the STLNET yet, sorry. I didn't however find much that
isn't done easily with the classes already in C#.

Also take a look at the System.Collections.ObjectModel.KeyedCollection
class (my favorite), because it's like a HashTable but includes an
indexer (Int), and you can add items without having to specify the key.

I really have no idea why they put it in the
System.Collections.ObjectModel namespace.

Regards, Wiebe
fstorck wrote:
Hi Wiebe,

ouch, looks pretty obvious. Ok, it's worth a try. BTW, anything heard of
this STLNET stuff. Is my intepretation correct ? If it's .Net based, it
should work fine with C# but I've not idea where to look for...
"Wiebe Tijsma" wrote:

>>I think it's easy to make a custom collection like this yourself based
on the existing ones, or you can use something like this:

Dictionary<string, List<myobject>map = new Dictionary<string,
List<myobject>>();

map.Add("CATEGORY1", new List<myobject>());
map["CATEGORY1"].Add(new myobject());
map["CATEGORY1"].Add(new myobject());
fstorck wrote:
>>>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());
map.Add("CATEGORY1", new myobject(); // <-- this is not possible here,
// because the Net 2.0 Dictionary
only supports
// unique keys.

</code>

It should support multiple objects per key.

Does anybody have a good solution / code for this ? And by the way, I heard
of STLNET ? But as I understood, this is only for C++ available ? Or does
this work under C# ( I found no documentation abaout this so far).

Thanks,
Florian
Aug 21 '06 #4
Thanks Wiebe,

sounds quite interesting to me!

"Wiebe Tijsma" wrote:
Hi,

I didn't look at the STLNET yet, sorry. I didn't however find much that
isn't done easily with the classes already in C#.

Also take a look at the System.Collections.ObjectModel.KeyedCollection
class (my favorite), because it's like a HashTable but includes an
indexer (Int), and you can add items without having to specify the key.

I really have no idea why they put it in the
System.Collections.ObjectModel namespace.

Regards, Wiebe
fstorck wrote:
Hi Wiebe,

ouch, looks pretty obvious. Ok, it's worth a try. BTW, anything heard of
this STLNET stuff. Is my intepretation correct ? If it's .Net based, it
should work fine with C# but I've not idea where to look for...
"Wiebe Tijsma" wrote:

>I think it's easy to make a custom collection like this yourself based
on the existing ones, or you can use something like this:

Dictionary<string, List<myobject>map = new Dictionary<string,
List<myobject>>();

map.Add("CATEGORY1", new List<myobject>());
map["CATEGORY1"].Add(new myobject());
map["CATEGORY1"].Add(new myobject());
fstorck wrote:

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());
map.Add("CATEGORY1", new myobject(); // <-- this is not possible here,
// because the Net 2.0 Dictionary
only supports
// unique keys.

</code>

It should support multiple objects per key.

Does anybody have a good solution / code for this ? And by the way, I heard
of STLNET ? But as I understood, this is only for C++ available ? Or does
this work under C# ( I found no documentation abaout this so far).

Thanks,
Florian

Aug 21 '06 #5
fstorck wrote:
Hi Wiebe,

ouch, looks pretty obvious. Ok, it's worth a try. BTW, anything heard of
this STLNET stuff. Is my intepretation correct ? If it's .Net based, it
should work fine with C# but I've not idea where to look for...
It just works with CLI/C++.
Here's a link: http://tinyurl.com/3t3ub
Aug 21 '06 #6
The only problem is that after two years we are still waiting for STLNET
:-).

Willy.

"Andreas Mueller" <me@privacy.netwrote in message
news:4k************@individual.net...
| fstorck wrote:
|
| Hi Wiebe,
| >
| ouch, looks pretty obvious. Ok, it's worth a try. BTW, anything heard of
| this STLNET stuff. Is my intepretation correct ? If it's .Net based, it
| should work fine with C# but I've not idea where to look for...
|
| It just works with CLI/C++.
| Here's a link: http://tinyurl.com/3t3ub
|
|
Aug 23 '06 #7

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

Similar topics

0
by: Jeff Engler | last post by:
with the following chunk of code: #include <map> using namespace std; void MultiMapTest() { std::multimap<const int, char *> myMultiMap; }
9
by: Dennis Jones | last post by:
Hi, Is there a way to iterate through a multimap in such a way as to encounter only the unique keys? In other words, since a multimap allows duplicate keys, I would like to iterate through the...
3
by: Przemek | last post by:
All, what is the efficient way to find all distinct keys in a multimap. I use the code template<class T1, class T2> set<T1> GetDistinctKeys(multimap<T1, T2> nMap) { T1 temp; multimap<T1,...
1
by: placid | last post by:
Hi all, i was just wondering if i have a class class A {}; then i want to use a multimap like, multimap<string,A*> as; //can i have a pointer to a A object ? A* aa = new A();
3
by: Jonay Aloat | last post by:
I need to implement the following. Shoul I use multimap or write a string hash class? ie Brand Product ========================== Samson ...
3
by: giuseppe.cannella | last post by:
i must create a muiltimap with 2 string , 1 int and 1 iterator to multimap itself how could define the typedef? thank
4
by: sks | last post by:
I have a question regarding std::multimap/iterators. At the SGI website, it says "Erasing an element from a multimap also does not invalidate any iterators, except, of course, for iterators that...
6
by: castironpi | last post by:
Is multimap just a syntax-checked dictionary of mutable sequences? Is def( a ): a= a trick or part of the language? It looks pretty sharp in variable-width.
1
by: ambarish.mitra | last post by:
Hi all, I have a multimap, where key is an int and the value is a class. I can insert into the multimap, but finding it difficult to retrieve the value when keys match. I can do this with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
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,...
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...

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.