Beispiel #1
0
    public WeightedDirectedGraph(int vertexCount)
    {
        var vertices = new Vertex[vertexCount];

        for (int id = 0; id < vertexCount; ++id)
        {
            vertices[id] = new Vertex(this, id);
        }

        Vertices = vertices;
    }
Beispiel #2
0
    public bool TryGetValue(Vertex key, out int value)
    {
        int keyIndex;

        if (_keyIndices.TryGetValue(key, out keyIndex))
        {
            value = _keyValuePairs[keyIndex].Value;
            return(true);
        }

        value = default(int);
        return(false);
    }
Beispiel #3
0
 public void AddEdge(Vertex startVertex, Vertex endVertex, int weight)
 => startVertex.AddNeighbor(endVertex, weight);
Beispiel #4
0
 public int Update(Vertex key, int value)
 => Update(new KeyValuePair <Vertex, int>(key, value));
Beispiel #5
0
 public int GetValue(Vertex key)
 => _keyValuePairs[_keyIndices[key]].Value;
Beispiel #6
0
 public bool Contains(Vertex key)
 => _keyIndices.ContainsKey(key);
Beispiel #7
0
 public void Add(Vertex key, int value)
 => Add(new KeyValuePair <Vertex, int>(key, value));
Beispiel #8
0
 public BinaryHeap(Vertex topKey, int topValue = 0)
 {
     _keyValuePairs.Add(new KeyValuePair <Vertex, int>(topKey, topValue));
     _keyIndices.Add(topKey, 0);
 }