tags:

views:

87

answers:

3

In my program (a program that assists with pathfinding), i need to store a list that contains entries consisting of a start node and an end node. A dictionary won't work as i cannot guarantee that the "key" (a node of course) will be unique. What is the best way to store this manner of data? Edit: i use C# and .Net 3.5.

A: 

If your language of choice supports sets, a set of (start, end) tuples is what you might be looking for.

scrible
Hmm.... i'll have to check if .net supports that.
RCIX
You could also emulate a set by using a dictionary with the (s.e) edges as keys. You can either ignore the values or use them for storing some useful info about the respective edges of your graph.
scrible
Darn, .net doesnt really support tuples or sets. Thanks for the idea though!
RCIX
+3  A: 

You might be better off simply using an array of structs. Or a vector of structs. This allows for non-unique nodes in your list. Vectors are a standard template in C++, but if C# doesn't support it, then an array should work fine.

chustar
+1  A: 

Would it be possible for you to use a List of KeyValuePair objects? Like this?

List<KeyValuePair<ObjectA, ObjectB>> list = new List<KeyValuePair<ObjectA, ObjectB>>();

I don't have VS in front of me right now, so I'm not sure if I have the syntax 100% right, but hopefully this helps.

jasonh
That might work, but what happens when i want to store 3 or more sets of related items?
RCIX
In that instance you would have to look at implementing a new object to provide to List<T>.
jasonh