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

G

Guest

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, myobject> map = 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
 
W

Wiebe Tijsma

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());
 
G

Guest

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 said:
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());

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, myobject> map = 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
 
W

Wiebe Tijsma

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

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...


:

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());

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, myobject> map = 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
 
G

Guest

Thanks Wiebe,

sounds quite interesting to me!

Wiebe Tijsma said:
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

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...


:

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, myobject> map = 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
 
A

Andreas Mueller

fstorck said:
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
 
W

Willy Denoyette [MVP]

The only problem is that after two years we are still waiting for STLNET
:).

Willy.

| 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
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top