views:

53

answers:

1

I need to implement a data structure in C#/SQL Server that is a little bit tree and a little bit graph. I can think of how to brute force this, but performance is very important. That is where I need help.

Here are the requirements:

1) There are n root nodes.

2) Each node can have n children.

3) Each node is a list.

4) Each node can be related to another node or to an item in the nodes list.

5) The relations (edges?) have a type. Specifically nodes can have a loose relationship (all books in the library with the same subject), generational relationships (a tweak to recipe), variant relationships (a translation of a book).

6) Each node can have a weight.

I am not very well versed in data structures that aren't in the standard lexicon (list, tree, hash table, dictionary, etc). So there may be something out there that I am just not aware of. When I google "graph sql server" I get a lot of links about pretty graph controls for reports. Performance is critical, there can potentially be millions of nodes that need to be brought into memory. I'd even take a LMGTFY with a properly crafted query since I seem unable to express what I want. Any starting point would help.

+1  A: 

How about looking into the following CodeProject project: http://www.codeproject.com/KB/recipes/DotNet2Datastructures.aspx

It has a nice Graph<T> Implementation (among others). The unaltered code won't help with the relations you are specifying, but if you'll add them yourself it might be a good starting point.

Omer