Here are the examples of the csharp api System.Collections.Generic.HashSet.Add(Vertex) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
19
Source : VertexCache.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public static Vertex Get(Vertex v)
{
if (!Enabled) return v;
Requests++;
//if (Requests % 100000 == 0)
//Console.WriteLine($"VertexCache: Requests={Requests}, Hits={Hits}");
if (Vertices.TryGetValue(v, out var result))
{
Hits++;
return result;
}
// not cached, add it
Vertices.Add(v);
return v;
}
19
Source : Point.cs
with GNU General Public License v3.0
from andy-wood
with GNU General Public License v3.0
from andy-wood
public void addVertex(Vertex v)
{
replacedert.IsNotNull (v);
_vertices.Add (v);
}
19
Source : ScriptMode.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
internal static void SelectSector(Sector sector, bool selected)
{
if (selected == sector.Selected)
{
return;
}
if (selected == true)
{
sector.Selected = true;
// "simple" in case of truth
foreach (Sidedef side in sector.Sidedefs)
{
side.Line.Selected = true;
side.Line.Start.Selected = true;
side.Line.End.Selected = true;
}
}
else
{
// false case less trivial, lines must remain selected if
// their other side is selected, and vertices must
// remain selected if they are connected to outside selected lines
sector.Selected = false;
HashSet<Vertex> deselect_vertices = new HashSet<Vertex>();
foreach (Sidedef side in sector.Sidedefs)
{
// skip disposed ones, of course
if (side.IsDisposed)
{
continue;
}
Linedef l = side.Line;
if (l.Back == null || l.Back.IsDisposed)
{
l.Selected = false;
}
else if (l.Front == null || l.Front.IsDisposed)
{
// this case probably shouldn't be possible but
// i want lua to be more careful about doing things
// that can cause crashes
l.Selected = false;
}
else
{
// 2sided
l.Selected = l.Front.Sector.Selected && l.Back.Sector.Selected;
deselect_vertices.Add(l.Start);
deselect_vertices.Add(l.End);
}
}
// we have to handle vertices in a second loop once the lines
// have already all been deselected if needed
foreach (Vertex v in deselect_vertices)
{
v.Selected = false;
foreach (Linedef l in v.Linedefs)
{
if (l.Selected)
{
v.Selected = true;
break;
}
}
// done w this vertex
}
} // done with true case
}
19
Source : Graph.cs
with MIT License
from mtrebi
with MIT License
from mtrebi
private void ChangeComponentId(Vertex<T> origin, int component_id) {
Stack<Vertex<T>> remaining_nodes = new Stack<Vertex<T>>();
HashSet<Vertex<T>> visited_nodes = new HashSet<Vertex<T>>();
remaining_nodes.Push(origin);
while (remaining_nodes.Count > 0) {
Vertex<T> node = remaining_nodes.Pop();
visited_nodes.Add(node);
node.component_id = component_id;
foreach(Edge<T> neighbor in node.neighbors) {
if (!visited_nodes.Contains(neighbor.node2)) {
remaining_nodes.Push(neighbor.node2);
}
}
}
}
19
Source : Prim.cs
with MIT License
from vazgriz
with MIT License
from vazgriz
public static List<Edge> MinimumSpanningTree(List<Edge> edges, Vertex start) {
HashSet<Vertex> openSet = new HashSet<Vertex>();
HashSet<Vertex> closedSet = new HashSet<Vertex>();
foreach (var edge in edges) {
openSet.Add(edge.U);
openSet.Add(edge.V);
}
closedSet.Add(start);
List<Edge> results = new List<Edge>();
while (openSet.Count > 0) {
bool chosen = false;
Edge chosenEdge = null;
float minWeight = float.PositiveInfinity;
foreach (var edge in edges) {
int closedVertices = 0;
if (!closedSet.Contains(edge.U)) closedVertices++;
if (!closedSet.Contains(edge.V)) closedVertices++;
if (closedVertices != 1) continue;
if (edge.Distance < minWeight) {
chosenEdge = edge;
chosen = true;
minWeight = edge.Distance;
}
}
if (!chosen) break;
results.Add(chosenEdge);
openSet.Remove(chosenEdge.U);
openSet.Remove(chosenEdge.V);
closedSet.Add(chosenEdge.U);
closedSet.Add(chosenEdge.V);
}
return results;
}
19
Source : Prim.cs
with MIT License
from vazgriz
with MIT License
from vazgriz
public static List<Edge> MinimumSpanningTree(List<Edge> edges, Vertex start) {
HashSet<Vertex> openSet = new HashSet<Vertex>();
HashSet<Vertex> closedSet = new HashSet<Vertex>();
foreach (var edge in edges) {
openSet.Add(edge.U);
openSet.Add(edge.V);
}
closedSet.Add(start);
List<Edge> results = new List<Edge>();
while (openSet.Count > 0) {
bool chosen = false;
Edge chosenEdge = null;
float minWeight = float.PositiveInfinity;
foreach (var edge in edges) {
int closedVertices = 0;
if (!closedSet.Contains(edge.U)) closedVertices++;
if (!closedSet.Contains(edge.V)) closedVertices++;
if (closedVertices != 1) continue;
if (edge.Distance < minWeight) {
chosenEdge = edge;
chosen = true;
minWeight = edge.Distance;
}
}
if (!chosen) break;
results.Add(chosenEdge);
openSet.Remove(chosenEdge.U);
openSet.Remove(chosenEdge.V);
closedSet.Add(chosenEdge.U);
closedSet.Add(chosenEdge.V);
}
return results;
}