简体   繁体   中英

How do I implement this graph/tree data structure in C#/SQL?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM