Kemsekov / GraphSharp

GraphSharp is a tool to study and use knowledge of graph theory in C#!
MIT License
38 stars 5 forks source link

Optimization done. #3

Closed Kemsekov closed 2 years ago

Kemsekov commented 2 years ago

I am once again done optimization for Graph. There is a lot of changes in how NodeBase are designed. Previously it was node's task to remember it's state and do some things. Now all this logic is moved into Graph class, so now Graph is NodeBase agnostic - > it can consume any custom NodeBase class, which is cool. Also I am moved from using Dictionary to store node's state. Now it is clear that you must not mess with how you create IEnumerable<NodeBase> for Graph class. It must follow the rule that every node with index M must have Id equal to M. This add some restrictions to how you can manage nodes. In the Graph constructor every node must have it's childrens begin part of IEnumerable<NodeBase>. And because of this you cannot for example extend nodes count in Graph instance or add to some NodeBase node which Id is out of range of nodes inside of Graph. <--- This action will cause IndexOutOfRange exception thrown in parallel. ActionVesitor API changed and now it have more controll over information about node it recieve. This update doubled perfomance of whole Graph, but now it will consume more RAM. Also I added one test with hand-written data to be sure that everything works.