22using System . Collections . Generic ;
33using Dijkstra . NET . PageRank ;
44using Dijkstra . NET . ShortestPath ;
5-
5+ using System . Linq ;
66namespace Dijkstra . NET . Graph
77{
88 public class Node < T , TEdgeCustom > : IPageRank , IDijkstra , INode < T , TEdgeCustom > where TEdgeCustom : IEquatable < TEdgeCustom >
99 {
10+ public Edge < T , TEdgeCustom > [ ] Edges ;
1011 private readonly HashSet < Node < T , TEdgeCustom > > _parents = new HashSet < Node < T , TEdgeCustom > > ( ) ;
1112 private readonly HashSet < uint > _children = new HashSet < uint > ( ) ;
12- private Edge < T , TEdgeCustom > [ ] _edges ;
1313
1414 internal Node ( uint key , T item , Graph < T , TEdgeCustom > graph )
1515 {
1616 Key = key ;
1717 Item = item ;
18- _edges = new Edge < T , TEdgeCustom > [ 5 ] ;
18+ Edges = new Edge < T , TEdgeCustom > [ 5 ] ;
1919 Graph = graph ;
2020 }
2121
@@ -46,17 +46,27 @@ public void EachEdge(Edge edge)
4646 {
4747 for ( int i = 0 ; i < EdgesCount ; i ++ )
4848 {
49- ref Edge < T , TEdgeCustom > e = ref _edges [ i ] ;
49+ ref Edge < T , TEdgeCustom > e = ref Edges [ i ] ;
5050
5151 edge ( e . Node . Key , e . Cost ) ;
5252 }
5353 }
54-
54+ /// <summary>
55+ /// Get custom info from node edges by edge key
56+ /// </summary>
57+ /// <param name="nodeEdgeKey">edge key</param>
58+ /// <returns>TEdgeCustom</returns>
59+ public TEdgeCustom GetFirstEdgeCustom ( int nodeEdgeKey )
60+ {
61+ return Edges . First ( c => c . Node . Key == nodeEdgeKey ) . Item ;
62+ }
63+
64+
5565 internal void AddEdge ( in Edge < T , TEdgeCustom > edge )
5666 {
57- if ( _edges . Length == EdgesCount )
67+ if ( Edges . Length == EdgesCount )
5868 {
59- int newSize = _edges . Length ;
69+ int newSize = Edges . Length ;
6070
6171 if ( EdgesCount < NodeConstants . MaxSize )
6272 {
@@ -69,10 +79,10 @@ internal void AddEdge(in Edge<T, TEdgeCustom> edge)
6979 newSize = bigSize < Int32 . MaxValue ? ( int ) bigSize : Int32 . MaxValue ;
7080 }
7181
72- Array . Resize ( ref _edges , newSize ) ;
82+ Array . Resize ( ref Edges , newSize ) ;
7383 }
7484
75- _edges [ EdgesCount ] = edge ;
85+ Edges [ EdgesCount ] = edge ;
7686 EdgesCount ++ ;
7787 _children . Add ( edge . Node . Key ) ;
7888 }
0 commit comments