2
2
using System . Collections . Generic ;
3
3
using Dijkstra . NET . PageRank ;
4
4
using Dijkstra . NET . ShortestPath ;
5
-
5
+ using System . Linq ;
6
6
namespace Dijkstra . NET . Graph
7
7
{
8
8
public class Node < T , TEdgeCustom > : IPageRank , IDijkstra , INode < T , TEdgeCustom > where TEdgeCustom : IEquatable < TEdgeCustom >
9
9
{
10
+ public Edge < T , TEdgeCustom > [ ] Edges ;
10
11
private readonly HashSet < Node < T , TEdgeCustom > > _parents = new HashSet < Node < T , TEdgeCustom > > ( ) ;
11
12
private readonly HashSet < uint > _children = new HashSet < uint > ( ) ;
12
- private Edge < T , TEdgeCustom > [ ] _edges ;
13
13
14
14
internal Node ( uint key , T item , Graph < T , TEdgeCustom > graph )
15
15
{
16
16
Key = key ;
17
17
Item = item ;
18
- _edges = new Edge < T , TEdgeCustom > [ 5 ] ;
18
+ Edges = new Edge < T , TEdgeCustom > [ 5 ] ;
19
19
Graph = graph ;
20
20
}
21
21
@@ -46,17 +46,27 @@ public void EachEdge(Edge edge)
46
46
{
47
47
for ( int i = 0 ; i < EdgesCount ; i ++ )
48
48
{
49
- ref Edge < T , TEdgeCustom > e = ref _edges [ i ] ;
49
+ ref Edge < T , TEdgeCustom > e = ref Edges [ i ] ;
50
50
51
51
edge ( e . Node . Key , e . Cost ) ;
52
52
}
53
53
}
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
+
55
65
internal void AddEdge ( in Edge < T , TEdgeCustom > edge )
56
66
{
57
- if ( _edges . Length == EdgesCount )
67
+ if ( Edges . Length == EdgesCount )
58
68
{
59
- int newSize = _edges . Length ;
69
+ int newSize = Edges . Length ;
60
70
61
71
if ( EdgesCount < NodeConstants . MaxSize )
62
72
{
@@ -69,10 +79,10 @@ internal void AddEdge(in Edge<T, TEdgeCustom> edge)
69
79
newSize = bigSize < Int32 . MaxValue ? ( int ) bigSize : Int32 . MaxValue ;
70
80
}
71
81
72
- Array . Resize ( ref _edges , newSize ) ;
82
+ Array . Resize ( ref Edges , newSize ) ;
73
83
}
74
84
75
- _edges [ EdgesCount ] = edge ;
85
+ Edges [ EdgesCount ] = edge ;
76
86
EdgesCount ++ ;
77
87
_children . Add ( edge . Node . Key ) ;
78
88
}
0 commit comments