本文整理汇总了C#中EdgeType.GetEdge方法的典型用法代码示例。如果您正苦于以下问题:C# EdgeType.GetEdge方法的具体用法?C# EdgeType.GetEdge怎么用?C# EdgeType.GetEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EdgeType
的用法示例。
在下文中一共展示了EdgeType.GetEdge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEdges
/// <summary>
/// Enumerates edges connected wih this vertex type
/// </summary>
/// <param name="etype">A type of edge type to look for</param>
/// <param name="dir">Direction of edge</param>
/// <returns></returns>
public IEnumerable<IEdge> GetEdges(EdgeType etype, Direction dir)
{
BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
switch (dir)
{
case Direction.Out:
if (m_tailToHeadEdges.TryGetValue(etype, out map))
foreach (var p1 in map)
foreach (var p2 in p1.Value)
{
Vertex vertex1 = GetVertex(p2.Key);
foreach (UInt64 l in p2.Value)
{
VertexId vId = (int)l;
Vertex vertex2 = p1.Key.GetVertex(vId);
EdgeId eId = (int)(l >> 32);
Edge edge = etype.GetEdge(eId, vertex1, vertex2);
yield return edge;
}
}
break;
case Direction.In:
if (m_headToTailEdges.TryGetValue(etype, out map))
foreach (var p1 in map)
foreach (var p2 in p1.Value)
{
Vertex vertex1 = GetVertex(p2.Key);
foreach (UInt64 l in p2.Value)
{
VertexId vId = (int)l;
Vertex vertex2 = p1.Key.GetVertex(vId);
EdgeId eId = (int)(l >> 32);
Edge edge = etype.GetEdge(eId, vertex2, vertex1);
yield return edge;
}
}
break;
case Direction.Both:
if (m_tailToHeadEdges.TryGetValue(etype, out map))
foreach (var p1 in map)
foreach (var p2 in p1.Value)
{
Vertex vertex1 = GetVertex(p2.Key);
foreach (UInt64 l in p2.Value)
{
VertexId vId = (int)l;
Vertex vertex2 = p1.Key.GetVertex(vId);
EdgeId eId = (int)(l >> 32);
Edge edge = etype.GetEdge(eId, vertex1, vertex2);
yield return edge;
}
};
if (m_headToTailEdges.TryGetValue(etype, out map))
foreach (var p1 in map)
foreach (var p2 in p1.Value)
{
Vertex vertex1 = GetVertex(p2.Key);
foreach (UInt64 l in p2.Value)
{
VertexId vId = (int)l;
Vertex vertex2 = p1.Key.GetVertex(vId);
EdgeId eId = (int)(l >> 32);
Edge edge = etype.GetEdge(eId, vertex2, vertex1);
yield return edge;
}
}
break;
}
}
示例2: Traverse
/// <summary>
/// Selects all neighbor Vertices from or to this vertex and for the given edge type.
/// </summary>
/// <param name="vertex1">the start Vertex</param>
/// <param name="etype">the type of edges to follow</param>
/// <param name="dir">Direction.</param>
/// <returns>Dictionary of vertex key with edge path(s) to vertex</returns>
internal Dictionary<Vertex, HashSet<Edge>> Traverse(Vertex vertex1, EdgeType etype, Direction dir)
{
Dictionary<Vertex, HashSet<Edge>> result = new Dictionary<Vertex, HashSet<Edge>>(10);
if (etype.Directed)
{
if (etype.Unrestricted)
{
foreach (var pair in etype.m_unrestrictedEdges)
{
UnrestrictedEdge edgeStruct = pair.Value;
bool headSameVertex = vertex1.VertexType == edgeStruct.m_headVertexType && vertex1.VertexId == edgeStruct.m_headVertexId;
bool tailSameVertex = vertex1.VertexType == edgeStruct.m_tailVertexType && vertex1.VertexId == edgeStruct.m_tailVertexId;
Vertex other;
if (headSameVertex)
{
VertexType vt = edgeStruct.m_tailVertexType;
other = vt.GetVertex(edgeStruct.m_tailVertexId);
}
else
{
if (tailSameVertex == false)
continue;
VertexType vt = edgeStruct.m_headVertexType;
other = vt.GetVertex(edgeStruct.m_headVertexId);
}
#if EdgeDebug
Edge edge = etype.GetEdge(graph, pair.Key, other, vertex1);
#else
Edge edge = new Edge(MyGraph, etype, pair.Key, vertex1, other);
#endif
AddToResult(result, other, edge);
}
}
else
foreach (var pair in etype.m_restrictedEdges)
{
UInt64 vertexVertex = pair.Value;
VertexId headVertexId = (VertexId) (vertexVertex >> 32);
VertexId tailVertexId = (Int32) (UInt32)vertexVertex;
bool headSameVertex = vertex1.VertexType == etype.HeadType && vertex1.VertexId == headVertexId;
bool tailSameVertex = vertex1.VertexType == etype.TailType && vertex1.VertexId == tailVertexId;
Vertex other;
if (headSameVertex)
{
VertexType vt = etype.TailType;
other = vt.GetVertex(tailVertexId);
}
else
{
if (tailSameVertex == false)
continue;
VertexType vt = etype.HeadType;
other = vt.GetVertex(headVertexId);
}
#if EdgeDebug
Edge edge = etype.GetEdge(g, pair.Key, other, vertex1);
#else
Edge edge = new Edge(MyGraph, etype, pair.Key, vertex1, other);
#endif
AddToResult(result, other, edge);
}
}
else
{
BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
BTreeSet<EdgeIdVertexId> set;
switch (dir)
{
case Direction.Out:
if (m_tailToHeadEdges.TryGetValue(etype, out map))
{
foreach (KeyValuePair<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> pair in map)
{
BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>> innerMap = pair.Value;
if (innerMap.TryGetValue(vertex1.VertexId, out set))
{
foreach (EdgeIdVertexId id in set)
{
Vertex vertex2 = new Vertex(MyGraph, pair.Key, (VertexId)id);
EdgeId eId = (EdgeId)(id >> 32);
Edge edge = etype.GetEdge(eId, vertex1, vertex2);
AddToResult(result, vertex2, edge);
}
}
}
}
break;
case Direction.In:
if (m_headToTailEdges.TryGetValue(etype, out map))
{
foreach (KeyValuePair<VertexType, BTreeMap<EdgeId, BTreeSet<EdgeIdVertexId>>> pair in map)
{
BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>> innerMap = pair.Value;
//.........这里部分代码省略.........