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
2009-06-05 03:20:52
Hmm.... i'll have to check if .net supports that.
RCIX
2009-06-05 03:28:32
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
2009-06-05 03:55:28
Darn, .net doesnt really support tuples or sets. Thanks for the idea though!
RCIX
2009-06-05 04:01:08
+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
2009-06-05 03:24:48
+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
2009-06-09 03:16:02