Alberto Cardoso

Hello.

Im trying to make a kind of object like the Hashmap with no unique key that I could loop trough it and get a string and the indexed string. Is actually two strings hash somthing like a datatable with two strings columns. The Dictionary class looked nice (Dictionary<string,string>) but it implements unique key too.

Thanks



Re: Visual C# General Hashmap without unique key.

TaylorMichaelL

If the keys aren't going to be unique then a hash doesn't really serve much purpose. The advantage of a dictionary over a regular collection is O(1) lookup based upon a unique key. Still sometimes conflicts are unavoidable. The Hashtable uses a bucket to store multiple values with the same key which appears to be sort of what you want.

Personally when I want to associate multiple pieces of info with a single key then I just create a dictionary of collection objects associated with a key. It is equivalent to a bucketed hashtable.

Be aware that v3.5 of .NET, I believe, will have new containers like what you are looking for. There is also a class library (Power Collections, I think) that contains some more theoretical data structures that you might find useful.

Michael Taylor - 8/21/07

http://p3net.mvps.org





Re: Visual C# General Hashmap without unique key.

Matthew Watson

This sort of collection (like a set, but allowing duplicates) is commonly referred to as a "Bag", for obvious reasons.

The PowerCollections library does indeed have a Bag<T> type. Everybody should be aware of the PowerCollections library IMHO; it can be extremely useful.

Get it here: http://www.wintellect.com/PowerCollections.aspx